diff --git a/src/lib/components/admin/Analytics/AnalyticsModelModal.svelte b/src/lib/components/admin/Analytics/AnalyticsModelModal.svelte index c9eb9cf3d..adcc6f33d 100644 --- a/src/lib/components/admin/Analytics/AnalyticsModelModal.svelte +++ b/src/lib/components/admin/Analytics/AnalyticsModelModal.svelte @@ -128,7 +128,9 @@ user_id: c.user_id, user_name: c.user_name })); - chatList = [...chatList, ...newChats]; + const existingIds = new Set(chatList.map((c) => c.id)); + const uniqueNewChats = newChats.filter((c) => !existingIds.has(c.id)); + chatList = [...chatList, ...uniqueNewChats]; allChatsLoaded = chats.length < PAGE_SIZE; } catch (err) { console.error('Failed to load more chats:', err); diff --git a/src/lib/components/admin/Users/UserList/UserChatsModal.svelte b/src/lib/components/admin/Users/UserList/UserChatsModal.svelte index 480f7ccf5..4ae550d0c 100644 --- a/src/lib/components/admin/Users/UserList/UserChatsModal.svelte +++ b/src/lib/components/admin/Users/UserList/UserChatsModal.svelte @@ -81,7 +81,9 @@ allChatsLoaded = newChatList.length === 0; if (newChatList.length > 0) { - chatList = [...chatList, ...newChatList]; + const existingIds = new Set(chatList.map((c) => c.id)); + const uniqueNewChats = newChatList.filter((c) => !existingIds.has(c.id)); + chatList = [...chatList, ...uniqueNewChats]; } chatListLoading = false; diff --git a/src/lib/components/chat/MessageInput/InputMenu/Knowledge.svelte b/src/lib/components/chat/MessageInput/InputMenu/Knowledge.svelte index 2df974c83..9037dfd4d 100644 --- a/src/lib/components/chat/MessageInput/InputMenu/Knowledge.svelte +++ b/src/lib/components/chat/MessageInput/InputMenu/Knowledge.svelte @@ -78,7 +78,9 @@ } if (selectedFileItems) { - selectedFileItems = [...selectedFileItems, ...pageItems]; + const existingIds = new Set(selectedFileItems.map((item) => item.id)); + const newItems = pageItems.filter((item) => !existingIds.has(item.id)); + selectedFileItems = [...selectedFileItems, ...newItems]; } else { selectedFileItems = pageItems; } @@ -137,7 +139,9 @@ } if (items) { - items = [...items, ...pageItems]; + const existingIds = new Set(items.map((item) => item.id)); + const newItems = pageItems.filter((item) => !existingIds.has(item.id)); + items = [...items, ...newItems]; } else { items = pageItems; } diff --git a/src/lib/components/layout/SearchModal.svelte b/src/lib/components/layout/SearchModal.svelte index b0fe91491..a8c1fd5f6 100644 --- a/src/lib/components/layout/SearchModal.svelte +++ b/src/lib/components/layout/SearchModal.svelte @@ -163,7 +163,9 @@ allChatsLoaded = newChatList.length === 0; if (newChatList.length > 0) { - chatList = [...chatList, ...newChatList]; + const existingIds = new Set(chatList.map((c) => c.id)); + const uniqueNewChats = newChatList.filter((c) => !existingIds.has(c.id)); + chatList = [...chatList, ...uniqueNewChats]; } chatListLoading = false; diff --git a/src/lib/components/layout/Sidebar.svelte b/src/lib/components/layout/Sidebar.svelte index b1cf1260d..2a8416b95 100644 --- a/src/lib/components/layout/Sidebar.svelte +++ b/src/lib/components/layout/Sidebar.svelte @@ -249,7 +249,9 @@ // once the bottom of the list has been reached (no results) there is no need to continue querying allChatsLoaded = newChatList.length === 0; - await chats.set([...($chats ? $chats : []), ...newChatList]); + const existingIds = new Set(($chats ?? []).map((c) => c.id)); + const uniqueNewChats = newChatList.filter((c) => !existingIds.has(c.id)); + await chats.set([...($chats ? $chats : []), ...uniqueNewChats]); chatListLoading = false; }; diff --git a/src/lib/components/notes/Notes.svelte b/src/lib/components/notes/Notes.svelte index bca2e4b51..4b4a208a8 100644 --- a/src/lib/components/notes/Notes.svelte +++ b/src/lib/components/notes/Notes.svelte @@ -221,7 +221,9 @@ } if (items) { - items = [...items, ...pageItems]; + const existingIds = new Set(items.map((item) => item.id)); + const newItems = pageItems.filter((item) => !existingIds.has(item.id)); + items = [...items, ...newItems]; } else { items = pageItems; } diff --git a/src/lib/components/workspace/Knowledge.svelte b/src/lib/components/workspace/Knowledge.svelte index 25b59d476..b2e117912 100644 --- a/src/lib/components/workspace/Knowledge.svelte +++ b/src/lib/components/workspace/Knowledge.svelte @@ -101,7 +101,9 @@ } if (items) { - items = [...items, ...pageItems]; + const existingIds = new Set(items.map((item) => item.id)); + const newItems = pageItems.filter((item) => !existingIds.has(item.id)); + items = [...items, ...newItems]; } else { items = pageItems; }