From 3c3e83b05ce2102efc6846c2ba91c383f38b272d Mon Sep 17 00:00:00 2001 From: Srijan Choudhary Date: Wed, 23 Apr 2014 00:56:40 +0530 Subject: [PATCH] Bug in API: Reply count should also filter by the after value passed --- isso/db/comments.py | 6 +++--- isso/views/comments.py | 5 ++++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/isso/db/comments.py b/isso/db/comments.py index 9c3bdda..c88947a 100644 --- a/isso/db/comments.py +++ b/isso/db/comments.py @@ -197,16 +197,16 @@ class Comments: return {'likes': likes + 1, 'dislikes': dislikes} return {'likes': likes, 'dislikes': dislikes + 1} - def reply_count(self, url): + def reply_count(self, url, after=0): """ Return comment count for main thread and all reply threads for one url. """ sql = [ 'SELECT comments.parent,count(*) FROM comments INNER JOIN threads ON', ' threads.uri=? AND comments.tid=threads.id', - ' AND comments.mode = 1 group by comments.parent;'] + ' AND comments.mode = 1 AND comments.created>? GROUP BY comments.parent;'] - return dict(self.db.execute(sql, [url]).fetchall()) + return dict(self.db.execute(sql, [url, after]).fetchall()) def count(self, *urls): """ diff --git a/isso/views/comments.py b/isso/views/comments.py index 608b436..658b381 100644 --- a/isso/views/comments.py +++ b/isso/views/comments.py @@ -323,6 +323,9 @@ class API(object): fetch_args={'uri': uri} if request.args.get('after'): fetch_args['after'] = request.args.get('after') + after = request.args.get('after') + else: + after = 0 if request.args.get('limit'): try: fetch_args['limit'] = int(request.args.get('limit')) @@ -342,7 +345,7 @@ class API(object): else: plain = False - reply_counts = self.comments.reply_count(uri) + reply_counts = self.comments.reply_count(uri, after) full_list = list(self.comments.fetch(**fetch_args)) root_list = [i for i in full_list if i['parent'] == root_id]