fix: large chats with no machine selected open slowly (#34963)

Opening a chat with no machine selected read through the whole conversation on every open, looking for a machine to restore. That is the normal case for a chat, so large chats opened about 45% slower. A chat that already saved its selection, with no machine or with a machine saved under its former terminal name, now opens without that extra pass. Agent chats with nothing saved still get their machine and folder back.

Fastest of seven opens of a 130 MB chat on SQLite:

<table>
<tr><th></th><th>Context Compaction off</th><th>Context Compaction on</th></tr>
<tr><td>dev before Terminals were renamed to Machines</td><td>0.316 s</td><td>0.429 s</td></tr>
<tr><td>dev</td><td>0.469 s</td><td>0.608 s</td></tr>
<tr><td>this fix</td><td>0.325 s</td><td>0.437 s</td></tr>
</table>

Fixes #34962
This commit is contained in:
Classic298 authored and GitHub committed 2026-11-24 23:11:30 +04:00
1 parent c56ba4e759
commit 90116cd36f
1 file changed
+3 -3
+3 -3
View File
@@ -4,7 +4,7 @@ import hashlib
import re
from urllib.parse import quote
from open_webui.utils.machines import machine_id_of, normalize_machine_id
from open_webui.utils.machines import normalize_machine_id
from open_webui.models.chat_messages import ChatMessages
from open_webui.models.chats import ChatModel, Chats
from open_webui.utils.auth import decode_token
@@ -19,8 +19,8 @@ def model_id(state):
async def ensure_chat_selections(chat):
data = chat.chat or {}
if all(key in data for key in ('models', 'working_directory')) and machine_id_of(data) is not None:
data = normalize_machine_id(dict(chat.chat or {}))
if all(key in data for key in ('models', 'machine_id', 'working_directory')):
return chat
state = await get_session(chat)
if not state: