mirror of
https://github.com/open-webui/open-webui.git
synced 2026-05-06 02:48:13 -05:00
[PR #15863] [MERGED] perf(db): Improve performance of db, especially sqlite #23963
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?
📋 Pull Request Information
Original PR: https://github.com/open-webui/open-webui/pull/15863
Author: @tcx4c70
Created: 7/19/2025
Status: ✅ Merged
Merged: 8/16/2025
Merged by: @tjbck
Base:
dev← Head:feat/sqlite-wal📝 Commits (3)
b23abcbfeat(db): Add DATABASE_ENABLE_SQLITE_WAL to enable SQLite WAL635cb8eperf(db): deduplicate update_user_last_active_by_id to reduce conflicts7bd7559refactor: format📊 Changes
4 files changed (+69 additions, -1 deletions)
View changed files
📝
backend/open_webui/env.py(+13 -0)📝
backend/open_webui/internal/db.py(+12 -1)📝
backend/open_webui/models/users.py(+3 -0)📝
backend/open_webui/utils/misc.py(+41 -0)📄 Description
Pull Request Checklist
Note to first-time contributors: Please open a discussion post in Discussions and describe your changes before submitting a pull request.
Before submitting, make sure you've checked the following:
devbranch.Changelog Entry
Description
This PR will improve db performance, especisally sqlite, by:
WALfor sqlite. It will only work for sqlite.user.last_active_atto reduce write conflicts. It will improve performance for all db theoretically.To avoid breaking changes, all the 2 improvements are disabled by default. User needs to enable them manually. I have enable both on my environment for 1 month, and they will improve performance significantly.
For more informantion, see discussion #15123.
Added
DATABASE_ENABLE_SQLITE_WALoption to enable SQLite WAL mode for better performance.deduplicateinbackend/open_webui/utils/misc.py, which prevents a decorated function from being called repeatedly within a specified time interval with the same arguments; repeated calls within the interval will returnNone.DATABASE_DEDUPLICATE_INTERVALconfiguration to control the deduplication interval (unit: second) for updatinguser.last_active_at.Breaking Changes
DATABASE_ENABLE_SQLITE_WALis enabled, it will enable WAL mode for sqlite (default: disabled).DATABASE_DEDUPLICATE_INTERVALis not 0,user.last_active_atmight not be accurate (default: 0).Screenshots or Videos
Before the improvements (or

DATABASE_ENABLE_SQLITE_WAL=falseandDATABASE_DEDUPLICATE_INTERVAL=0)Only enable WAL (

DATABASE_ENABLE_SQLITE_WAL=trueandDATABASE_DEDUPLICATE_INTERVAL=0)Enable both (


DATABASE_ENABLE_SQLITE_WAL=trueandDATABASE_DEDUPLICATE_INTERVAL=10)(In the second picture, there is no
UPDATEoperation since it's in 10s interval)Contributor License Agreement
By submitting this pull request, I confirm that I have read and fully agree to the Contributor License Agreement (CLA), and I am providing my contributions under its terms.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.