mirror of
https://github.com/open-webui/open-webui.git
synced 2026-09-10 22:43:29 +00:00
fix: add deterministic ordering to chat_ids pagination query to prevent duplicates (#22383)
This commit is contained in:
parent
459a60a242
commit
d1975b740b
1 changed files with 5 additions and 1 deletions
|
|
@ -292,9 +292,13 @@ class ChatMessageTable:
|
|||
query = query.filter(ChatMessage.created_at <= end_date)
|
||||
|
||||
# Group by chat_id and order by most recent message in each chat
|
||||
# Secondary sort on chat_id ensures deterministic pagination
|
||||
# (prevents duplicates across pages when timestamps tie)
|
||||
chat_ids = (
|
||||
query.group_by(ChatMessage.chat_id)
|
||||
.order_by(func.max(ChatMessage.created_at).desc())
|
||||
.order_by(
|
||||
func.max(ChatMessage.created_at).desc(), ChatMessage.chat_id
|
||||
)
|
||||
.offset(skip)
|
||||
.limit(limit)
|
||||
.all()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue