open-webui/backend/open_webui/models
Classic298 2e4c232807
perf: update chat tags via the meta column instead of round-tripping the blob (#27382)
update_chat_tags_by_id runs at the end of every completion when tag generation is enabled (the default). It loaded the full chat row including the multi-megabyte blob, mutated only meta.tags, committed, then refreshed the row, which re-fetched and re-parsed the entire blob a second time, and finally validated the whole thing into a ChatModel that its only caller (the auto-tagging handler) discards. add_chat_tag_by_id_and_user_id_and_tag_name had the same shape for a one-tag append, and orphan cleanup issued one COUNT query per removed tag.

Both tag writers now select only the meta column and issue a column-level UPDATE, never touching the blob; the single-tag path also skips the write entirely when the tag is already present. Orphan detection batches all per-tag counts into one round trip using one scalar subquery per tag with the exact same dialect-specific EXISTS filters as before; the existing single-tag count delegates to the batch helper so there is one implementation.

Benchmark (real SQLite DB, 200-message chat, ~600 KB blob):

| metric | before | after |
| --- | --- | --- |
| auto-tag update, 3 tags replaced | 12.85 ms | 7.36 ms |

The absolute saving grows with chat size since the blob no longer gets fetched, parsed, re-fetched and validated at all.

Functionally verified against a fresh database: tag replacement normalizes and filters the none placeholder, creates missing tag rows and leaves the blob untouched; orphaned tags are deleted while tags still referenced by other chats survive; single-tag add is idempotent; batch counts agree with the single count including unknown tags; unknown chat ids return None.
2026-07-27 02:21:59 -04:00
..
access_grants.py chore: format 2026-07-27 00:12:47 -04:00
auths.py perf: drop redundant session.refresh calls after commit across the model layer (#27381) 2026-07-23 18:08:00 -05:00
automations.py refac 2026-07-26 19:34:41 -04:00
calendar.py chore: format 2026-07-27 00:12:47 -04:00
channels.py perf: drop redundant session.refresh calls after commit across the model layer (#27381) 2026-07-23 18:08:00 -05:00
chat_messages.py perf: drop redundant session.refresh calls after commit across the model layer (#27381) 2026-07-23 18:08:00 -05:00
chats.py perf: update chat tags via the meta column instead of round-tripping the blob (#27382) 2026-07-27 02:21:59 -04:00
config.py refac 2026-07-26 18:46:39 -04:00
feedbacks.py perf: drop redundant session.refresh calls after commit across the model layer (#27381) 2026-07-23 18:08:00 -05:00
files.py perf: drop redundant session.refresh calls after commit across the model layer (#27381) 2026-07-23 18:08:00 -05:00
folders.py refac 2026-07-26 19:34:41 -04:00
functions.py fix: prevent startup crash when function/tool has null user_id (#26850) 2026-07-24 00:00:37 -05:00
groups.py refac: modernize type annotations (PEP 604 / PEP 585) 2026-05-12 17:10:15 +09:00
knowledge.py feat: sortable title and updated at columns on the knowledge workspace page (#27457) 2026-07-26 18:19:31 -04:00
memories.py refac 2026-07-24 01:54:36 -04:00
messages.py refac 2026-06-29 13:03:14 -05:00
models.py perf: drop redundant session.refresh calls after commit across the model layer (#27381) 2026-07-23 18:08:00 -05:00
notes.py refac 2026-07-27 02:11:10 -04:00
oauth_sessions.py perf: drop redundant session.refresh calls after commit across the model layer (#27381) 2026-07-23 18:08:00 -05:00
prompt_history.py perf: drop redundant session.refresh calls after commit across the model layer (#27381) 2026-07-23 18:08:00 -05:00
prompts.py perf: drop redundant session.refresh calls after commit across the model layer (#27381) 2026-07-23 18:08:00 -05:00
shared_chats.py feat(ui): add 'Unshare All Shared Chats' button to Shared Chats modal (#25848) 2026-06-17 03:06:41 +02:00
skills.py perf: drop redundant session.refresh calls after commit across the model layer (#27381) 2026-07-23 18:08:00 -05:00
tags.py perf: drop redundant session.refresh calls after commit across the model layer (#27381) 2026-07-23 18:08:00 -05:00
tools.py fix: prevent startup crash when function/tool has null user_id (#26850) 2026-07-24 00:00:37 -05:00
users.py refac 2026-07-24 01:44:30 -04:00