Skip to content

Commit

Permalink
db: Set reply sorting to oldest
Browse files Browse the repository at this point in the history
  • Loading branch information
ggtylerr committed Sep 10, 2024
1 parent 6f3874c commit f07826c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ Bugfixes & Improvements
- Make 'text' field in 'comments' table NOT NULL and handling data migration (`#1019`_, pkvach)
- Python 3.12 support (`#1015`_, ix5)
- Disable Postbox submit button on click, enable after response (`#993`_, pkvach)
- Set reply sorting to always be oldest (`#1035`_, ggtylerr)

.. _#951: https://github.com/posativ/isso/pull/951
.. _#967: https://github.com/posativ/isso/pull/967
Expand All @@ -64,6 +65,7 @@ Bugfixes & Improvements
.. _#1019: https://github.com/isso-comments/isso/pull/1019
.. _#1015: https://github.com/isso-comments/isso/pull/1015
.. _#993: https://github.com/isso-comments/isso/pull/993
.. _#1035: https://github.com/isso-comments/isso/pull/1035

0.13.1.dev0 (2023-02-05)
------------------------
Expand Down
3 changes: 2 additions & 1 deletion docs/docs/reference/client-config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,8 @@ data-isso-sorting
- ``oldest``: Bring oldest comments to the top
- ``upvotes``: Bring most liked comments to the top

Default sorting is ``oldest``.
Default sorting is ``oldest``. As of 0.13.1, replies are always sorted as
``oldest``.

.. versionadded:: 0.13.1

Expand Down
12 changes: 6 additions & 6 deletions isso/db/comments.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,16 +217,16 @@ def fetchall(self, mode=5, after=0, parent='any', order_by='id',

# custom sanitization
if order_by not in ['id', 'created', 'modified', 'likes', 'dislikes', 'tid']:
sql.append('ORDER BY ')
sql.append("comments.created")
sql.append('ORDER BY CASE WHEN comments.parent IS NOT NULL THEN comments.created END, ')
sql.append('comments.created')
if not asc:
sql.append(' DESC')
else:
sql.append('ORDER BY ')
sql.append('ORDER BY CASE WHEN comments.parent IS NOT NULL THEN comments.created END, ')
sql.append('comments.' + order_by)
if not asc:
sql.append(' DESC')
sql.append(", comments.created")
sql.append(', comments.created')

if limit:
sql.append('LIMIT ?,?')
Expand Down Expand Up @@ -257,8 +257,8 @@ def fetch(self, uri, mode=5, after=0, parent='any',

# custom sanitization
if order_by not in ['id', 'created', 'modified', 'likes', 'dislikes', 'karma']:
order_by = 'id'
sql.append('ORDER BY ')
order_by = 'created'
sql.append('ORDER BY CASE WHEN comments.parent IS NOT NULL THEN comments.created END, ')
sql.append(order_by)
if not asc:
sql.append(' DESC')
Expand Down

0 comments on commit f07826c

Please sign in to comment.