Bug in API: Reply count should also filter by the after value passed
This commit is contained in:
parent
8fdceeaafb
commit
3c3e83b05c
@ -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):
|
||||
"""
|
||||
|
@ -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]
|
||||
|
Loading…
Reference in New Issue
Block a user