From 85e3ed57f15d94054e96c31e06188b9fff4f8f84 Mon Sep 17 00:00:00 2001 From: pablonyx Date: Thu, 27 Feb 2025 09:35:42 -0800 Subject: [PATCH] Order chat sessions by time updated, not created (#4143) * order chat sessions by time updated, not created * quick update * k --- backend/ee/onyx/server/query_history/api.py | 1 + backend/onyx/db/chat.py | 2 +- backend/onyx/server/features/folder/api.py | 1 + backend/onyx/server/openai_assistants_api/threads_api.py | 2 ++ backend/onyx/server/query_and_chat/chat_backend.py | 1 + backend/onyx/server/query_and_chat/models.py | 1 + backend/onyx/server/query_and_chat/query_backend.py | 1 + web/src/app/chat/folders/FolderList.tsx | 2 +- web/src/app/chat/interfaces.ts | 2 ++ web/src/app/chat/lib.tsx | 6 +++--- web/src/app/chat/shared/[chatId]/SharedChatDisplay.tsx | 2 +- web/src/lib/chat/fetchChatData.ts | 2 +- 12 files changed, 16 insertions(+), 7 deletions(-) diff --git a/backend/ee/onyx/server/query_history/api.py b/backend/ee/onyx/server/query_history/api.py index b7dfbb6e06..7f1e96a71a 100644 --- a/backend/ee/onyx/server/query_history/api.py +++ b/backend/ee/onyx/server/query_history/api.py @@ -138,6 +138,7 @@ def get_user_chat_sessions( name=chat.description, persona_id=chat.persona_id, time_created=chat.time_created.isoformat(), + time_updated=chat.time_updated.isoformat(), shared_status=chat.shared_status, folder_id=chat.folder_id, current_alternate_model=chat.current_alternate_model, diff --git a/backend/onyx/db/chat.py b/backend/onyx/db/chat.py index 0da54b8adb..62d29827ae 100644 --- a/backend/onyx/db/chat.py +++ b/backend/onyx/db/chat.py @@ -168,7 +168,7 @@ def get_chat_sessions_by_user( if not include_onyxbot_flows: stmt = stmt.where(ChatSession.onyxbot_flow.is_(False)) - stmt = stmt.order_by(desc(ChatSession.time_created)) + stmt = stmt.order_by(desc(ChatSession.time_updated)) if deleted is not None: stmt = stmt.where(ChatSession.deleted == deleted) diff --git a/backend/onyx/server/features/folder/api.py b/backend/onyx/server/features/folder/api.py index 503c66258f..813c5eabdc 100644 --- a/backend/onyx/server/features/folder/api.py +++ b/backend/onyx/server/features/folder/api.py @@ -49,6 +49,7 @@ def get_folders( name=chat_session.description, persona_id=chat_session.persona_id, time_created=chat_session.time_created.isoformat(), + time_updated=chat_session.time_updated.isoformat(), shared_status=chat_session.shared_status, folder_id=folder.id, ) diff --git a/backend/onyx/server/openai_assistants_api/threads_api.py b/backend/onyx/server/openai_assistants_api/threads_api.py index a487b6ca99..a06c64448b 100644 --- a/backend/onyx/server/openai_assistants_api/threads_api.py +++ b/backend/onyx/server/openai_assistants_api/threads_api.py @@ -147,9 +147,11 @@ def list_threads( name=chat.description, persona_id=chat.persona_id, time_created=chat.time_created.isoformat(), + time_updated=chat.time_updated.isoformat(), shared_status=chat.shared_status, folder_id=chat.folder_id, current_alternate_model=chat.current_alternate_model, + current_temperature_override=chat.temperature_override, ) for chat in chat_sessions ] diff --git a/backend/onyx/server/query_and_chat/chat_backend.py b/backend/onyx/server/query_and_chat/chat_backend.py index 505047c6da..c2043ff78e 100644 --- a/backend/onyx/server/query_and_chat/chat_backend.py +++ b/backend/onyx/server/query_and_chat/chat_backend.py @@ -119,6 +119,7 @@ def get_user_chat_sessions( name=chat.description, persona_id=chat.persona_id, time_created=chat.time_created.isoformat(), + time_updated=chat.time_updated.isoformat(), shared_status=chat.shared_status, folder_id=chat.folder_id, current_alternate_model=chat.current_alternate_model, diff --git a/backend/onyx/server/query_and_chat/models.py b/backend/onyx/server/query_and_chat/models.py index 2c68b38f1f..d7db7cf8c9 100644 --- a/backend/onyx/server/query_and_chat/models.py +++ b/backend/onyx/server/query_and_chat/models.py @@ -181,6 +181,7 @@ class ChatSessionDetails(BaseModel): name: str | None persona_id: int | None = None time_created: str + time_updated: str shared_status: ChatSessionSharedStatus folder_id: int | None = None current_alternate_model: str | None = None diff --git a/backend/onyx/server/query_and_chat/query_backend.py b/backend/onyx/server/query_and_chat/query_backend.py index 25deaabc18..2706b89b08 100644 --- a/backend/onyx/server/query_and_chat/query_backend.py +++ b/backend/onyx/server/query_and_chat/query_backend.py @@ -159,6 +159,7 @@ def get_user_search_sessions( name=sessions_with_documents_dict[search.id], persona_id=search.persona_id, time_created=search.time_created.isoformat(), + time_updated=search.time_updated.isoformat(), shared_status=search.shared_status, folder_id=search.folder_id, current_alternate_model=search.current_alternate_model, diff --git a/web/src/app/chat/folders/FolderList.tsx b/web/src/app/chat/folders/FolderList.tsx index 1d63f943be..61e532f83a 100644 --- a/web/src/app/chat/folders/FolderList.tsx +++ b/web/src/app/chat/folders/FolderList.tsx @@ -168,7 +168,7 @@ const FolderItem = ({ }; const folders = folder.chat_sessions.sort((a, b) => { - return a.time_created.localeCompare(b.time_created); + return a.time_updated.localeCompare(b.time_updated); }); // Determine whether to show the trash can icon diff --git a/web/src/app/chat/interfaces.ts b/web/src/app/chat/interfaces.ts index 6f614c7d25..f5daad62b2 100644 --- a/web/src/app/chat/interfaces.ts +++ b/web/src/app/chat/interfaces.ts @@ -70,6 +70,7 @@ export interface ChatSession { name: string; persona_id: number; time_created: string; + time_updated: string; shared_status: ChatSessionSharedStatus; folder_id: number | null; current_alternate_model: string; @@ -123,6 +124,7 @@ export interface BackendChatSession { persona_icon_shape: number | null; messages: BackendMessage[]; time_created: string; + time_updated: string; shared_status: ChatSessionSharedStatus; current_temperature_override: number | null; current_alternate_model?: string; diff --git a/web/src/app/chat/lib.tsx b/web/src/app/chat/lib.tsx index 62c908d555..e2ea1b4a5f 100644 --- a/web/src/app/chat/lib.tsx +++ b/web/src/app/chat/lib.tsx @@ -48,10 +48,10 @@ export function getChatRetentionInfo( ): ChatRetentionInfo { // If `maximum_chat_retention_days` isn't set- never display retention warning. const chatRetentionDays = settings.maximum_chat_retention_days || 10000; - const createdDate = new Date(chatSession.time_created); + const updatedDate = new Date(chatSession.time_updated); const today = new Date(); const daysFromCreation = Math.ceil( - (today.getTime() - createdDate.getTime()) / (1000 * 3600 * 24) + (today.getTime() - updatedDate.getTime()) / (1000 * 3600 * 24) ); const daysUntilExpiration = chatRetentionDays - daysFromCreation; const showRetentionWarning = @@ -419,7 +419,7 @@ export function groupSessionsByDateRange(chatSessions: ChatSession[]) { }; chatSessions.forEach((chatSession) => { - const chatSessionDate = new Date(chatSession.time_created); + const chatSessionDate = new Date(chatSession.time_updated); const diffTime = today.getTime() - chatSessionDate.getTime(); const diffDays = diffTime / (1000 * 3600 * 24); // Convert time difference to days diff --git a/web/src/app/chat/shared/[chatId]/SharedChatDisplay.tsx b/web/src/app/chat/shared/[chatId]/SharedChatDisplay.tsx index 73fbc36397..a59249e7cd 100644 --- a/web/src/app/chat/shared/[chatId]/SharedChatDisplay.tsx +++ b/web/src/app/chat/shared/[chatId]/SharedChatDisplay.tsx @@ -206,7 +206,7 @@ export function SharedChatDisplay({ {chatSession.description || `Unnamed Chat`}

- {humanReadableFormat(chatSession.time_created)} + {humanReadableFormat(chatSession.time_updated)}

- new Date(b.time_created).getTime() - new Date(a.time_created).getTime() + new Date(b.time_updated).getTime() - new Date(a.time_updated).getTime() ); let documentSets: DocumentSet[] = [];