Commit Graph

324 Commits

Author SHA1 Message Date
Timothy Jaeryang Baek
b1048fc9bc refac 2026-03-07 20:22:01 -06:00
Classic298
223c14f48b fix: add deterministic tiebreaker to all paginated chat queries (#22387)
Add Chat.id as a secondary sort key to all paginated chat queries
that use offset/limit pagination. When multiple chats share the same
updated_at timestamp, the database does not guarantee a stable order
across page boundaries, causing chats to appear on multiple pages.

This produces duplicate keys in the Svelte sidebar each-block
(each_key_duplicate error). Adding Chat.id as a tiebreaker ensures
fully deterministic ordering.

Extends the fix from #22383 (which addressed get_chat_ids_by_model_id)
to all remaining paginated chat queries.
2026-03-07 20:16:50 -06:00
Timothy Jaeryang Baek
3ceaa107ab chore: format 2026-03-07 20:14:32 -06:00
Timothy Jaeryang Baek
8913f37c3d enh: create subfolder
Co-Authored-By: Colin Chen <1207878+silenceroom@users.noreply.github.com>
2026-03-07 19:45:43 -06:00
Classic298
d1975b740b fix: add deterministic ordering to chat_ids pagination query to prevent duplicates (#22383) 2026-03-07 20:19:44 -05:00
Timothy Jaeryang Baek
6d9996e599 refac 2026-03-06 20:12:37 -06:00
Classic298
d93cb3658d perf(models): batch-fetch function valves to eliminate N+1 queries (#22301)
* perf(models): batch-fetch function valves to eliminate N+1 queries

get_action_priority() called Functions.get_function_valves_by_id()
individually for every action on every model — an N+1 query pattern
that issued one DB round-trip per (action x model) pair.

Add Functions.get_function_valves_by_ids() that fetches all valves in
a single WHERE IN query, then look up each action's valves from the
pre-fetched dict inside get_action_priority().

No functional change — same priority resolution, same sort order.

* Update models.py

* Update models.py
2026-03-06 15:56:01 -06:00
Timothy Jaeryang Baek
80ad5fd2d0 refac 2026-03-01 14:06:26 -06:00
Timothy Jaeryang Baek
2cbba2a28a chore: format 2026-03-01 13:29:06 -06:00
Timothy Jaeryang Baek
0fff2fbcab refac 2026-03-01 13:23:39 -06:00
Timothy Jaeryang Baek
fcff9c3afd refac 2026-03-01 13:20:55 -06:00
Timothy Jaeryang Baek
345f3e3559 refac 2026-02-25 15:15:59 -06:00
Timothy Jaeryang Baek
87d33f6e18 refac 2026-02-25 14:52:41 -06:00
Classic298
82959cec88 Update oauth_sessions.py (#21794) 2026-02-24 17:05:47 -06:00
Timothy Jaeryang Baek
9478c5e7ac refac 2026-02-24 17:04:07 -06:00
Timothy Jaeryang Baek
538501c88d refac 2026-02-24 15:19:49 -06:00
Timothy Jaeryang Baek
3d99de6771 enh: access grant level perms 2026-02-23 15:49:05 -06:00
Timothy Jaeryang Baek
f4a1d99f00 refac 2026-02-23 12:52:46 -06:00
Timothy Jaeryang Baek
9044abf3bb chore: format 2026-02-23 01:40:53 -06:00
Timothy Jaeryang Baek
0185f3340d refac 2026-02-22 17:28:01 -06:00
Timothy Jaeryang Baek
b48594a166 refac 2026-02-21 16:27:25 -06:00
Timothy Jaeryang Baek
631e30e22d refac 2026-02-21 15:35:34 -06:00
Classic298
45e23c3ad0 perf: eliminate 2 redundant full chat deserialization on every message send (#21596)
* perf: eliminate 2 redundant full chat deserialization on every message send (#162)

Problem:
Every message send triggered get_chat_by_id_and_user_id which loads the
entire Chat row — including the potentially massive JSON blob containing
the full conversation history — even when the caller only needed a
simple yes/no ownership check or a single column value.

Two call sites in the message-send hot path were doing this:

1. main.py ownership verification: loaded the entire chat object including
   all message history JSON, then checked `if chat is None`. The JSON blob
   was immediately discarded — only the existence of the row mattered.

2. middleware.py folder check: loaded the entire chat object including all
   message history JSON, then read only `chat.folder_id` — a plain column
   on the chat table that requires zero JSON parsing.

Fix:
- Added `chat_exists_by_id_and_user_id()`: uses SQL EXISTS subquery which
  returns a boolean without loading any row data. The database can satisfy
  this from the primary key index alone.

- Added `get_chat_folder_id()`: queries only the `folder_id` column via
  `db.query(Chat.folder_id)`, which tells SQLAlchemy to SELECT only that
  single column instead of the entire row.

Both new methods preserve the same error handling semantics (return
False/None on exception) and user_id filtering (ownership check) as
the original get_chat_by_id_and_user_id.

Impact:
- Best case (typical): eliminates deserializing 2 full chat JSON blobs per
  message send. For long conversations (hundreds of messages with tool
  calls, images, file attachments), this blob can be multiple megabytes.
- Worst case: no regression — the new queries are strictly cheaper than
  the old ones (less data transferred, less Python object construction,
  no Pydantic model_validate overhead).
- The 3 remaining full chat loads in process_chat_payload (load_messages_from_db,
  add_file_context, chat_image_generation_handler) are left untouched as
  they genuinely need the full history and require separate analysis.

* Address maintainer feedback: rename method and inline call (#166)

- Rename chat_exists_by_id_and_user_id -> is_chat_owner
- Remove intermediate chat_owned variable; call is_chat_owner directly in if condition
2026-02-21 14:53:31 -06:00
Timothy Jaeryang Baek
ae05586fda refac: oauth session management 2026-02-20 16:49:43 -06:00
Timothy Jaeryang Baek
8c485b260f refac 2026-02-19 16:53:21 -06:00
Classic298
d664922feb Avoid loading full chat JSON blob for pinned/archived/shared list endpoints (#21591)
Co-authored-by: Tim Baek <tim@openwebui.com>
2026-02-19 16:48:23 -06:00
Classic298
3db6d49e57 Query title column directly in get_chat_title_by_id instead of loading full chat (#157) (#21590)
Previously loaded the entire ChatModel (including the full conversation JSON
blob) just to extract the title string. Now queries only the Chat.title
column directly, which is already a top-level DB column.
2026-02-19 16:41:46 -06:00
Timothy Jaeryang Baek
139f02a9d9 refac 2026-02-19 16:04:41 -06:00
Classic298
35763a352c Optimize shared chats list to use column projection (#163) (#21614)
The GET /chats/shared endpoint was loading full Chat rows including
the entire conversation history JSON blob, only to discard it and
return SharedChatResponse (id, title, share_id, timestamps). Now
uses with_entities() to select only the 5 needed columns, avoiding
deserialization of potentially large chat JSON for every shared chat.
2026-02-19 15:50:03 -06:00
Timothy Jaeryang Baek
3dd44c4f19 refac 2026-02-18 15:23:50 -06:00
Timothy Jaeryang Baek
094ed0b48c fix: prompts delete 2026-02-18 14:58:39 -06:00
Timothy Jaeryang Baek
e5e39be90f refac 2026-02-16 13:14:40 -06:00
Timothy Jaeryang Baek
09dc28df1e chore: format 2026-02-16 00:43:32 -06:00
Timothy Jaeryang Baek
c748c3ede7 refac 2026-02-16 00:41:36 -06:00
Timothy Jaeryang Baek
33308022f0 refac 2026-02-15 23:57:40 -06:00
Timothy Jaeryang Baek
7e224e4a53 refac 2026-02-13 18:26:03 -06:00
Timothy Jaeryang Baek
626d236d13 chore: format 2026-02-13 15:00:39 -06:00
Timothy Jaeryang Baek
a9b8677cc0 refac 2026-02-13 14:59:05 -06:00
Classic298
0f3f68b0c4 enh (#21362) 2026-02-13 14:56:53 -06:00
Timothy Jaeryang Baek
d1d1efe212 refac: scim 2026-02-13 14:27:11 -06:00
Timothy Jaeryang Baek
b7549d2f6c refac: defer profile 2026-02-13 14:08:07 -06:00
Timothy Jaeryang Baek
589c4e64c1 refac 2026-02-13 13:56:29 -06:00
Timothy Jaeryang Baek
ca6b18ab5c refac: is_user_active 2026-02-13 13:40:59 -06:00
Timothy Jaeryang Baek
b4c3f54f96 fix: skills postgres issue 2026-02-13 11:24:08 -06:00
Timothy Jaeryang Baek
7bda6bf767 fix: PostgreSQL cannot use get_chat_ids_by_model_id
Co-Authored-By: EntropyYue <164553692+EntropyYue@users.noreply.github.com>
2026-02-13 11:20:26 -06:00
Timothy Jaeryang Baek
96c07f44a8 refac 2026-02-11 16:45:47 -06:00
Timothy Jaeryang Baek
f376d4f378 chore: format 2026-02-11 16:24:11 -06:00
Timothy Jaeryang Baek
773787c74c refac 2026-02-11 16:16:41 -06:00
Timothy Jaeryang Baek
c8cbdc8f7f refac 2026-02-11 15:24:12 -06:00
Timothy Jaeryang Baek
64c37ab968 refac 2026-02-11 15:12:37 -06:00