mirror of
https://github.com/open-webui/open-webui.git
synced 2026-05-06 19:08:59 -05:00
[GH-ISSUE #4035] [bug/perf] large db, slow query to /chats/
#13471
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @thearyadev on GitHub (Jul 22, 2024).
Original GitHub issue: https://github.com/open-webui/open-webui/issues/4035
Bug Report
Description
Bug Summary:
i've been having this issue where the
/chats/endpoint takes like 30+ seconds to respond with the chats list.i did some poking, and queried the database using
sqlite3. theselect * from chatsquery takes forever to complete, with a huge amount of encoded file data dumped.i'm assuming this is image/file data. When i upload an image (in this case, multiple images) the size of the database increases, and the
/chats/endpoint takes longer to resolve.Deleting all chats resolves the slow downs.
the query used by the backend loads the entire table for a single user, which in my case, contained hundreds of images.
result from sqlite3 query:

Steps to Reproduce:
/chatsrequest.Expected Behavior:
the query should be quick. In a separate environment, with ~100 chats, the query time is like 1/100th of a second.
Actual Behavior:
the query took 30 seconds.
Environment
possible solutions
(just thinking out loud)
@Yanyutin753 commented on GitHub (Jul 22, 2024):
I also believe that file information should not be stored in a database, but the URL should be stored, providing a bold hypothesis that we can consider accessing oss or local file urls to solve this problem
@thearyadev commented on GitHub (Jul 22, 2024):
I'm working on a solution for this right now.
I think dealing with the database bloat is important, but not directly related to this issue.
Even in the case that the database is not massive, there is a lot of excess data that is being loaded into memory, when all that is required is the
titleandidof the chat.Pagination is also a valid solution, but a single query for chats is not very large. The data is fairly small, and the benefit gained from scroll-pagination in the sidebar is minimal in comparison to the complexity it adds (i tried experimenting with this, was not fun)
my proposed solution
with_entitiesensures the sql query only requests the data it needs, and not all of the chat data. I'm not sure where else this function is used, so i think it may be best to add another function specifically returning theChatTitleIdResponsedataclass.I can open a PR for this later today.
@tjbck commented on GitHub (Jul 24, 2024):
Related: https://github.com/open-webui/open-webui/issues/2078
@Classic298 commented on GitHub (Aug 22, 2025):
Hey everyone, this PR might be interesting to you:
https://github.com/open-webui/open-webui/pull/16520
Testing wanted