Postgres treats NULL as larger than anything else, so the REST series view starts
with all messages that never had a reply. Sort by id instead for stability and
to get more obvious results.
In the web view, place non-replied messages last and sort them by descending date.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
api/rest.py | 2 +-
www/views.py | 6 ++----
2 files changed, 3 insertions(+), 5 deletions(-)
diff --git a/api/rest.py b/api/rest.py
index de02857..b723997 100644
--- a/api/rest.py
+++ b/api/rest.py
@@ -540,7 +540,7 @@ class PatchewSearchFilter(filters.BaseFilterBackend):
class SeriesViewSet(BaseMessageViewSet):
serializer_class = SeriesSerializer
- queryset = Message.objects.filter(topic__isnull=False).order_by("-last_reply_date")
+ queryset = Message.objects.filter(topic__isnull=False).order_by("-id")
filter_backends = (PatchewSearchFilter,)
search_fields = (SEARCH_PARAM,)
diff --git a/www/views.py b/www/views.py
index e20aa91..d8c40af 100644
--- a/www/views.py
+++ b/www/views.py
@@ -176,13 +176,11 @@ def prepare_navigate_list(cur, *path):
def render_series_list_page(request, query, search=None, project=None, keywords=[]):
sort = request.GET.get("sort")
if sort == "replied":
- sortfield = "-last_reply_date"
+ query = query.order_by(F('last_reply_date').desc(nulls_last=True), '-date')
order_by_reply = True
else:
- sortfield = "-date"
+ query = query.order_by('-date')
order_by_reply = False
- if sortfield:
- query = query.order_by(sortfield)
query = query.prefetch_related("topic")
cur_page = get_page_from_request(request)
start = (cur_page - 1) * PAGE_SIZE
--
2.31.1
_______________________________________________
Patchew-devel mailing list
Patchew-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/patchew-devel