Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor comment sorting to use 'karma' instead of 'likes' in API and…
Browse files Browse the repository at this point in the history
… database queries
pkvach committed Apr 25, 2024
1 parent 78f954a commit 6f61ab4
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions isso/db/comments.py
Original file line number Diff line number Diff line change
@@ -225,7 +225,7 @@ def fetch(self, uri, mode=5, after=0, parent='any',
"""
Return comments for :param:`uri` with :param:`mode`.
"""
sql = ['SELECT comments.* FROM comments INNER JOIN threads ON',
sql = ['SELECT comments.*, likes - dislikes AS karma FROM comments INNER JOIN threads ON',
' threads.uri=? AND comments.tid=threads.id AND (? | comments.mode) = ?',
' AND comments.created>?']

@@ -239,7 +239,7 @@ def fetch(self, uri, mode=5, after=0, parent='any',
sql_args.append(parent)

# custom sanitization
if order_by not in ['id', 'created', 'modified', 'likes', 'dislikes']:
if order_by not in ['id', 'created', 'modified', 'likes', 'dislikes', 'karma']:
order_by = 'id'
sql.append('ORDER BY ')
sql.append(order_by)
2 changes: 1 addition & 1 deletion isso/views/comments.py
Original file line number Diff line number Diff line change
@@ -901,7 +901,7 @@ def fetch(self, environ, request, uri):
args['order_by'] = 'created'
args['asc'] = 1
elif sort == 'upvotes':
args['order_by'] = 'likes'
args['order_by'] = 'karma'
args['asc'] = 0

try:

0 comments on commit 6f61ab4

Please sign in to comment.