From a572cf48426f607548f1f3da350bcf2fe143eb0e Mon Sep 17 00:00:00 2001 From: silentoplayz Date: Sun, 28 Sep 2025 13:25:34 -0400 Subject: [PATCH] feat: add backend handling for unarchiving all chats The previous implementation for unarchiving all chats in `ArchivedChatsModal.svelte` was inefficient, as it sent a separate request for each chat, which could potentially overload the server. This commit introduces a new backend endpoint, `/chats/unarchive/all`, to handle the bulk unarchiving of all chats for a user with a single API call. The frontend has been updated to use this new endpoint, resolving the performance issue by minimizing the number of requests to the server. --- backend/open_webui/models/chats.py | 9 +++++ backend/open_webui/routers/chats.py | 10 ++++++ src/lib/apis/chats/index.ts | 32 +++++++++++++++++ .../layout/ArchivedChatsModal.svelte | 35 ++++++++++++++----- 4 files changed, 77 insertions(+), 9 deletions(-) diff --git a/backend/open_webui/models/chats.py b/backend/open_webui/models/chats.py index 083d044053..98b1166ce4 100644 --- a/backend/open_webui/models/chats.py +++ b/backend/open_webui/models/chats.py @@ -366,6 +366,15 @@ class ChatTable: except Exception: return False + def unarchive_all_chats_by_user_id(self, user_id: str) -> bool: + try: + with get_db() as db: + db.query(Chat).filter_by(user_id=user_id).update({"archived": False}) + db.commit() + return True + except Exception: + return False + def update_chat_share_id_by_id( self, id: str, share_id: Optional[str] ) -> Optional[ChatModel]: diff --git a/backend/open_webui/routers/chats.py b/backend/open_webui/routers/chats.py index 65f912ff53..1f065988fe 100644 --- a/backend/open_webui/routers/chats.py +++ b/backend/open_webui/routers/chats.py @@ -361,6 +361,16 @@ async def archive_all_chats(user=Depends(get_verified_user)): return Chats.archive_all_chats_by_user_id(user.id) +############################ +# UnarchiveAllChats +############################ + + +@router.post("/unarchive/all", response_model=bool) +async def unarchive_all_chats(user=Depends(get_verified_user)): + return Chats.unarchive_all_chats_by_user_id(user.id) + + ############################ # GetSharedChatById ############################ diff --git a/src/lib/apis/chats/index.ts b/src/lib/apis/chats/index.ts index a19220278d..b8073d94fa 100644 --- a/src/lib/apis/chats/index.ts +++ b/src/lib/apis/chats/index.ts @@ -33,6 +33,38 @@ export const createNewChat = async (token: string, chat: object, folderId: strin return res; }; +export const unarchiveAllChats = async (token: string) => { + let error = null; + + const res = await fetch(`${WEBUI_API_BASE_URL}/chats/unarchive/all`, { + method: 'POST', + headers: { + Accept: 'application/json', + 'Content-Type': 'application/json', + ...(token && { authorization: `Bearer ${token}` }) + } + }) + .then(async (res) => { + if (!res.ok) throw await res.json(); + return res.json(); + }) + .then((json) => { + return json; + }) + .catch((err) => { + error = err.detail; + + console.error(err); + return null; + }); + + if (error) { + throw error; + } + + return res; +}; + export const importChat = async ( token: string, chat: object, diff --git a/src/lib/components/layout/ArchivedChatsModal.svelte b/src/lib/components/layout/ArchivedChatsModal.svelte index 93a73b394b..791aa8c9fe 100644 --- a/src/lib/components/layout/ArchivedChatsModal.svelte +++ b/src/lib/components/layout/ArchivedChatsModal.svelte @@ -1,19 +1,26 @@ -