fix: paged lists repeat some entries and skip others (#35281)

The admin user list, feedbacks, groups, the workspace models, prompts and skills lists, prompt history, notes, shared chats, automations, calendar search, analytics messages and SCIM user listings are loaded page by page, and when many rows share the sorted value (a role, a bulk-import timestamp, a rating) the database is free to return those ties in a different order for each page. On PostgreSQL 16, paging through 300 users sorted by role showed 16 users twice and never showed 16 others, and with an id tiebreaker every user showed up exactly once. These lists now sort by each entry's id as a last step, as the chats and knowledge lists already do.

Fixes #35280
This commit is contained in:
Classic298 authored and GitHub committed 2026-11-30 18:41:44 +04:00
1 parent 00ad719de0
commit 2d03af81ef
12 files changed
+24 -8

No files matched your search

+3 -1
View File
@@ -701,6 +701,8 @@ class NoteTable:
else:
stmt = stmt.order_by(Note.updated_at.desc())
stmt = stmt.order_by(Note.id)
# Count BEFORE pagination
count_result = await db.execute(select(func.count()).select_from(stmt.subquery()))
total = count_result.scalar()
@@ -747,7 +749,7 @@ class NoteTable:
user_groups = await Groups.get_groups_by_member_id(user_id, db=db, include_inherited=True)
user_group_ids = [group.id for group in user_groups]
stmt = select(Note).order_by(Note.updated_at.desc())
stmt = select(Note).order_by(Note.updated_at.desc(), Note.id)
stmt = self._has_permission(db, stmt, {'user_id': user_id, 'group_ids': user_group_ids}, permission)
if skip is not None: