mirror of
https://github.com/open-webui/open-webui.git
synced 2026-07-10 04:20:44 +02:00
perf: use set for O(1) lookup in insert_chat_files dedupe (#23800)
Convert chat_message_file_ids from list to set so the membership test in the comprehension is O(1) instead of O(m), turning the dedupe from O(n*m) into O(n+m). Also replace the redundant set([...]) with a set comprehension. https://claude.ai/code/session_01Le3NnqNhcgaJvFrDZGqmwe Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -1536,11 +1536,11 @@ class ChatTable:
|
||||
if not file_ids:
|
||||
return None
|
||||
|
||||
chat_message_file_ids = [
|
||||
chat_message_file_ids = {
|
||||
item.id for item in await self.get_chat_files_by_chat_id_and_message_id(chat_id, message_id, db=db)
|
||||
]
|
||||
}
|
||||
# Remove duplicates and existing file_ids
|
||||
file_ids = list(set([file_id for file_id in file_ids if file_id and file_id not in chat_message_file_ids]))
|
||||
file_ids = list({file_id for file_id in file_ids if file_id and file_id not in chat_message_file_ids})
|
||||
if not file_ids:
|
||||
return None
|
||||
|
||||
|
||||
Reference in New Issue
Block a user