Commit Graph
197 Commits
Author SHA1 Message Date
Timothy Jaeryang Baek d4e8493cc5 refac 2026-11-07 20:31:42 +09:00
Timothy Jaeryang Baek 18f7633afa refac 2026-11-06 13:40:53 +09:00
Classic298 c165ee14f0 perf: opening a chat no longer loads the whole conversation to mark it read (#33666)
Every time a chat is opened, the server marks it as read, and to do so it loaded and parsed the full chat, images included, just to save the last-read time. Marking a chat as unread and removing a tag from a chat did the same. These now touch only the few chat fields they change, which makes them 4 to 6 times faster on large chats.

Measured on SQLite, best of 7 runs, sizes are the chat as stored in the database:

| Chat | Action | Before | After |
| --- | --- | --- | --- |
| 7 MB, text only | open (mark read) | 19.8 ms | 3.5 ms |
| 7 MB, text only | mark as unread | 20.7 ms | 3.5 ms |
| 7 MB, text only | remove tag | 21.2 ms | 3.4 ms |
| 49 MB, with images | open (mark read) | 122.2 ms | 30.0 ms |
| 49 MB, with images | mark as unread | 124.2 ms | 29.1 ms |
| 49 MB, with images | remove tag | 120.5 ms | 28.6 ms |
2026-11-05 22:38:25 +09:00
Classic298 323f7353bf perf: chat access checks no longer load the whole conversation (#33667)
Typing indicators, sending a message, shared links, comments and file access all check whether the user may access the chat, and each check loaded the full chat, images included, only to look at who owns it and which folder it is in. On large chats that delayed every other request on the same server process by up to a few hundred milliseconds per check. The check now reads just those few fields, and who gets access is unchanged.

Measured on SQLite, best of 5 runs, sizes are the chat as stored in the database:

| Chat | Checked for | Before | After |
| --- | --- | --- | --- |
| 7 MB, text only | the chat owner | 34.6 ms | 0.36 ms |
| 7 MB, text only | a user with access through a shared folder | 35.1 ms | 2.58 ms |
| 57 MB, with images | the chat owner | 249.8 ms | 0.72 ms |
| 57 MB, with images | a user with access through a shared folder | 249.0 ms | 2.80 ms |
2026-11-04 05:33:17 +09:00
Timothy Jaeryang Baek ddb43c83ba refac 2026-11-02 12:45:15 +09:00
Timothy Jaeryang Baek d99ec1c02c refac 2026-11-02 08:48:51 +09:00
Timothy Jaeryang Baek 3814b7b2f1 refac 2026-10-31 16:50:01 +09:00
Timothy Jaeryang Baek 9d1b4ef362 refac 2026-10-30 16:01:47 +09:00
Timothy Jaeryang Baek 44a9d499db refac 2026-10-29 17:39:31 +09:00
Classic298 226dca18cd fix: member's chat loses its pin when the shared folder owner moves it (#33342)
When the owner of a shared folder moved a chat a member created to another folder inside the shared folder, the chat lost the member's pin and dropped out of their Pinned list. The owner's move now keeps the member's pin, just as it already keeps the chat's unread status for them. Moving your own chat into a folder still unpins it, as before, so it shows up in that folder.

Fixes #33341
2026-10-29 08:05:16 +09:00
Classic298 40a9fba81f feat: moving a chat into or out of a folder keeps its last activity date (#33327)
Filing an old chat into a folder made it look recently active: it jumped to the top of the sidebar under Today, and a batch of old chats sorted into folders ended up ordered by when each was moved. Moving a chat into or out of a folder now keeps its last activity date, so it is sorted and grouped by when it was really last active. Moving your own chat still clears its unread dot as before, and when the owner of a shared folder reorganizes your chat within it, the chat no longer turns unread for you.

Closes #30362
2026-10-29 05:21:30 +09:00
G30 02821c5058 fix: a model's Chats tab in Analytics follows the User group filter (#33207) 2026-10-26 17:27:32 +09:00
Timothy Jaeryang Baek 7b303cf496 refac 2026-10-26 07:24:36 +09:00
Classic298 e1e31973f0 perf: renaming a folder or deleting all chats takes seconds when many users are online (#32888)
* perf: renaming a folder or deleting all chats takes seconds when many users are online

Renaming, sharing, moving or deleting a folder, and deleting all chats, each made the server recheck access for every chat that any online user had open in a browser tab, one database lookup at a time, before the request finished, and every one of those open chats reloaded its contents afterwards. Any user can do these, so with a few thousand people online every such click took several seconds and reloaded everyone's open chat. Owners keep access to their own chats (a role change or account deletion already disconnects them), so the recheck now skips owners entirely, with no lookup and no reload, and only checks people viewing someone else's chat and chats that no longer exist. Anyone who lost access is still removed from the chat as before.

Postgres 16, one open chat per online user, 2% of them viewing someone else's chat, time for a folder rename (the other actions above run the same recheck):

| Online users | No Redis, before | No Redis, after | Redis, before | Redis, after |
| --- | --- | --- | --- | --- |
| 1,000 | 2.2 s | 0.12 s | 2.5 s | 0.23 s |
| 3,000 | 6.9 s | 0.60 s | 7.7 s | 0.78 s |

* refac: collect the open chats with a plain loop

Same behaviour, the owner lookup now reads more plainly.

* refac: shorten the owner comment in the chat access sweep
2026-10-25 07:21:47 +09:00
Timothy Jaeryang Baek 2262073146 refac 2026-10-24 04:50:12 +09:00
Timothy Jaeryang Baek b4a58be193 refac 2026-10-21 09:15:15 +09:00
G30 97f5c4e973 fix: Archive All Chats takes chats out of their folders, so deleting a folder no longer deletes them (#32647) 2026-10-21 03:18:03 +09:00
Classic298 93ba628f3a fix: generated images never show up after the user answers the model's question or approves a tool (#32680)
When the model asked the user a question, or a tool call was approved or rejected, the reply was saved in a way that broke adding anything to it later in the same turn. If the model then generated an image, the image was created but never shown, the tool returned "unsupported operand type(s) for +: 'NoneType' and 'list'" and the model kept retrying, generating more hidden images. Progress status updates for that reply were also silently dropped. Both now work after a question or tool approval.

Fixes #32678
2026-10-21 02:39:39 +09:00
Timothy Jaeryang Baek 4b81b12ed4 chore: format 2026-10-16 15:20:15 +04:00
Timothy Jaeryang Baek 788a61180b refac 2026-10-16 04:20:14 +04:00
G30 29289f5ba6 fix: deleting a message in the middle of a chat keeps the earlier messages in the model's context (#32332) 2026-10-14 18:30:31 +04:00
Timothy Jaeryang Baek 35c927ba99 refac 2026-10-14 14:59:41 +04:00
G30 99a9f60b9f fix: a model added before Regenerate stays side by side after reload (#32326) 2026-10-13 16:46:01 +04:00
Classic298 113a64ad1a perf: speed up one-word chat search (#32268)
Chat search checks the whole query and each word in it separately. With a single word those are the same check, so every chat got searched twice. It is now searched once, with the same results. On PostgreSQL with 2164 chats (533 MB of chat data) a one-word search is about 40% faster:

| search | before | after |
|---|---|---|
| proxy | 6.0 s | 3.6 s |
| opnsense | 6.1 s | 3.8 s |
| no match | 5.4 s | 3.0 s |

Refs #32266
2026-10-12 23:32:52 +04:00
Timothy Jaeryang Baek 93723bd315 refac 2026-10-10 22:39:57 +04:00
G30 78550396da fix: keep a tag's name when the last chat using it is archived (#32200) 2026-10-10 20:30:15 +04:00
Timothy Jaeryang Baek d04f78b3bf refac 2026-10-10 20:29:50 +04:00
Classic298 641c82df19 fix: automations, timers and sub-agents fail with "Message already exists" (#32177)
Automation runs, timers and sub-agents stopped getting a reply after the shared chats rework: the chat shows an empty answer and the run fails with `409 Message already exists or has an invalid ID.` Each of them creates the empty answer before asking the model, and the backend began refusing to fill an answer that is already in the chat; the server-side API flow in the docs and API calls without a user message broke the same way. Such an empty answer is now filled in again when it belongs to the same user and answers the same message, and API calls without a user message work as before, saving the reply on its own as the docs describe. A firing timer or sub-agent also no longer cancels the chat's other timers that are set to stop when the user writes next. Answers that are already finished, or that belong to another user in a shared chat, are still refused.

Fixes #32066
2026-10-10 20:02:54 +04:00
Timothy Jaeryang Baek 6cfd6987e5 refac 2026-10-08 14:58:06 +04:00
Timothy Jaeryang Baek de73bb830a refac 2026-10-08 14:30:07 +04:00
Timothy Jaeryang Baek 093bfce2b6 refac 2026-10-07 00:39:16 +04:00
Timothy Jaeryang Baek d8659c237c refac 2026-10-05 10:46:08 +04:00
Classic298 3d43a497b5 fix: shared chats can't open new files attached together with a file already in the chat (#31650)
When files were attached to a chat message and one of them was already attached to that chat (on the same message or another one), none of the new files were recorded as part of the chat, and nothing showed up in the logs. The sender still saw every file in their own chat, but anyone opening a shared copy of the chat could not open the new ones. Files already attached to the chat are now skipped and the new ones are recorded normally.

Fixes #31648
2026-09-30 21:03:32 +04:00
G30 d4d04dca0d fix: keep a cloned chat in a shared folder the user can write to (#31370) 2026-09-30 19:59:11 +04:00
G30 ffe21bef8d fix: remove the share links of chats deleted along with their folder (#31306) 2026-09-26 07:27:49 +04:00
G30 95d6af44d7 fix: mark imported and cloned chats as read (#30754) 2026-09-23 23:32:14 -04:00
Classic298 49b25506dd perf: stop round-tripping the whole chat to read or write one message (#28184)
Long conversations get progressively more expensive to stream into. Every message-level write reloads the entire chat JSON, walks every string in it for a null-byte sanitisation pass and rewrites the whole column, and reading a single message loads and validates the whole chat too. The websocket event emitter reads and then writes, so one message event round-trips the full conversation twice to change a few hundred bytes.

Reading one message now selects only history.messages out of the JSON column and indexes it in Python, so the rest of the chat is neither loaded nor model-validated. Writing one message now sanitises only what is actually entering the chat, plus the title column that is mirrored off the blob, instead of re-walking a conversation that was already sanitised when it was written. Legacy rows are still healed on read by get_chat_by_id, which is unchanged.

One behaviour change: chats written before the null-byte sanitisation existed can still hold null bytes in the stored JSON. Those rows used to be rewritten clean as a side effect of any message write, and are now cleaned when the chat is read instead. The visible consequence is that the message write and delete endpoints echo back the updated chat, and for such a legacy row that echo now carries the raw null bytes rather than stripped ones, until the next read of that chat heals it. A GET of the chat is unaffected, and title, the one text column that PostgreSQL cannot store a null byte in, is still sanitised on every write.

Measured on SQLite with a 10.8 MB chat (3000 messages): a single-message upsert is 227 ms before the branch and 173 ms after, and the legacy single-message read is 135 ms before and 79 ms after. The whole-blob scan the delete path used to run costs 5.40 ms on a 1.8 MB chat and 38.79 ms on the 10.8 MB one, and is gone.

Ref https://github.com/open-webui/open-webui/issues/28169

### Contributor License Agreement

<!--
🚨 DO NOT DELETE THE TEXT BELOW 🚨
Keep the "Contributor License Agreement" confirmation text intact.
Deleting it will trigger the CLA-Bot to INVALIDATE your PR.

Your PR will NOT be reviewed or merged until you check the box below confirming that you have read and agree to the terms of the CLA.
-->

- [x] By submitting this pull request, I confirm that I have read and fully agree to the [Contributor License Agreement (CLA)](https://github.com/open-webui/open-webui/blob/main/CONTRIBUTOR_LICENSE_AGREEMENT), and I am providing my contributions under its terms.

> [!NOTE]
> Deleting the CLA section will lead to immediate closure of your PR and it will not be merged in.
2026-09-21 10:11:38 -04:00
Timothy Jaeryang Baek 5fb869db22 refac 2026-09-21 08:59:39 -04:00
G30 402a187e82 fix: return no chats when a folder search term matches no folder (#30273) 2026-09-20 23:39:54 -05:00
G30 9e293a58ea fix: label the search modal's archive action Unarchive for archived chats and report what happened (#30177) 2026-09-19 10:02:11 -05:00
G30 4d01f1ebed fix: keep the archived state and chat variables when importing a chat export (#30155) 2026-09-18 19:29:30 -04:00
Timothy Jaeryang Baek 508de20779 refac 2026-09-06 17:27:30 -04:00
Timothy Jaeryang Baek 59d3c5b064 refac 2026-08-31 10:37:46 -04:00
Timothy Jaeryang Baek 8ed5487693 refac 2026-08-31 00:41:11 -04:00
Timothy Jaeryang Baek 873fb741c2 refac 2026-08-31 00:39:16 -04:00
Timothy Jaeryang Baek 1c13fedb16 refac 2026-08-25 13:18:38 -04:00
Timothy Jaeryang Baek 9dff5e9327 refac 2026-08-24 18:37:39 -04:00
Timothy Jaeryang Baek 536b9edec0 refac 2026-08-24 18:35:04 -04:00
Classic298 16c2a9eda4 fix: index the chat queries that make large SQLite instances unusable (#27663)
The timer scheduler polls once a second and cancels on every message send and chat open, the sidebar lists chats ordered by `updated_at`, and the folder badges count unread chats per folder. None of those could be served by an index, so each call read most of the `chat` table, and because `meta` sits after the chat payload column SQLite had to walk every row's overflow pages to get there. On a large history that stalls the sidebar, every chat switch and every send, and the idle poll alone burns about a quarter of a CPU core.

Timers now keep their due time in a dedicated `chat.timer_at` column behind a partial index, and the chat list, unread and unfinished-reply queries each get an index matching their filter and ordering. Existing pending timers are backfilled from their meta by the migration. Dropping the `internal` and `type` checks also makes a forked timer chat inert, where a fork used to copy `meta` verbatim and become a second claim target that could fire a duplicate timer.

Measured on SQLite, same rows returned:

| query | before | after |
|---|---|---|
| idle timer poll (2000 chats, 0.43 GB) | 170 ms | 0.04 ms |
| cancel on send and chat open (4000 chats, 377 MB) | 200 ms | 0.04 ms |
| sidebar chat list (15000 chats, 1.26 GB) | 157 ms | 1.8 ms |
| folder unread badges (15000 chats, 1.4 GB) | 54 ms | 0.2 ms |

PostgreSQL 17 serves all of them as index-only scans with no sort node. Exercised through fresh install, upgrade with seeded data, downgrade and re-upgrade on SQLite and PostgreSQL 17.

Fixes #27622
2026-08-23 16:11:54 -05:00
Timothy Jaeryang Baek 7d4747dfd7 refac 2026-08-20 13:13:51 -07:00