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:
Target branch: Please verify that the pull request targets the dev branch.
Description: Provide a concise description of the changes made in this pull request.
Changelog: Ensure a changelog entry following the format of Keep a Changelog is added at the bottom of the PR description.
Documentation: Have you updated relevant documentation Open WebUI Docs, or other documentation sources?
Dependencies: Are there any new dependencies? Have you updated the dependency versions in the documentation?
Testing: Have you written and run sufficient tests to validate the changes?
Code review: Have you performed a self-review of your code, addressing any coding standard issues and ensuring adherence to the project's coding standards?
Prefix: To clearly categorize this pull request, prefix the pull request title using one of the following:
BREAKING CHANGE: Significant changes that may affect compatibility
build: Changes that affect the build system or external dependencies
ci: Changes to our continuous integration processes or workflows
chore: Refactor, cleanup, or other non-functional code changes
docs: Documentation update or addition
feat: Introduces a new feature or enhancement to the codebase
fix: Bug fix or error correction
i18n: Internationalization or localization changes
perf: Performance improvement
refactor: Code restructuring for better maintainability, readability, or scalability
style: Changes that do not affect the meaning of the code (white space, formatting, missing semi-colons, etc.)
test: Adding missing tests or correcting existing tests
WIP: Work in progress, a temporary label for incomplete or ongoing work
Changelog Entry
Description
This PR will improve db performance, especisally sqlite, by:
Enable WAL for sqlite. It will only work for sqlite.
Reduce the update number of user.last_active_at to 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.
Add DATABASE_ENABLE_SQLITE_WAL option to enable SQLite WAL mode for better performance.
Introduce a new decorator deduplicate in backend/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 return None.
Add DATABASE_DEDUPLICATE_INTERVAL configuration to control the deduplication interval (unit: second) for updating user.last_active_at.
Breaking Changes
If DATABASE_ENABLE_SQLITE_WAL is enabled, it will enable WAL mode for sqlite (default: disabled).
If DATABASE_DEDUPLICATE_INTERVAL is not 0, user.last_active_at might not be accurate (default: 0).
Screenshots or Videos
Before the improvements (or DATABASE_ENABLE_SQLITE_WAL=false and DATABASE_DEDUPLICATE_INTERVAL=0)
Only enable WAL (DATABASE_ENABLE_SQLITE_WAL=true and DATABASE_DEDUPLICATE_INTERVAL=0)
Enable both (DATABASE_ENABLE_SQLITE_WAL=true and DATABASE_DEDUPLICATE_INTERVAL=10)
(In the second picture, there is no UPDATE operation 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.
## 📋 Pull Request Information
**Original PR:** https://github.com/open-webui/open-webui/pull/15863
**Author:** [@tcx4c70](https://github.com/tcx4c70)
**Created:** 7/19/2025
**Status:** ✅ Merged
**Merged:** 8/16/2025
**Merged by:** [@tjbck](https://github.com/tjbck)
**Base:** `dev` ← **Head:** `feat/sqlite-wal`
---
### 📝 Commits (3)
- [`b23abcb`](https://github.com/open-webui/open-webui/commit/b23abcbfe55f0357674ec139cbf781b31db0a9a0) feat(db): Add DATABASE_ENABLE_SQLITE_WAL to enable SQLite WAL
- [`635cb8e`](https://github.com/open-webui/open-webui/commit/635cb8e3ff0208724ff122b37128ae4e42f7ff05) perf(db): deduplicate update_user_last_active_by_id to reduce conflicts
- [`7bd7559`](https://github.com/open-webui/open-webui/commit/7bd7559bfe490c71d9601e35ae119d788a90c495) refactor: format
### 📊 Changes
**4 files changed** (+69 additions, -1 deletions)
<details>
<summary>View changed files</summary>
📝 `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)
</details>
### 📄 Description
# Pull Request Checklist
### Note to first-time contributors: Please open a discussion post in [Discussions](https://github.com/open-webui/open-webui/discussions) and describe your changes before submitting a pull request.
**Before submitting, make sure you've checked the following:**
- [x] **Target branch:** Please verify that the pull request targets the `dev` branch.
- [x] **Description:** Provide a concise description of the changes made in this pull request.
- [x] **Changelog:** Ensure a changelog entry following the format of [Keep a Changelog](https://keepachangelog.com/) is added at the bottom of the PR description.
- [ ] **Documentation:** Have you updated relevant documentation [Open WebUI Docs](https://github.com/open-webui/docs), or other documentation sources?
- [x] **Dependencies:** Are there any new dependencies? Have you updated the dependency versions in the documentation?
- [x] **Testing:** Have you written and run sufficient tests to validate the changes?
- [x] **Code review:** Have you performed a self-review of your code, addressing any coding standard issues and ensuring adherence to the project's coding standards?
- [x] **Prefix:** To clearly categorize this pull request, prefix the pull request title using one of the following:
- **BREAKING CHANGE**: Significant changes that may affect compatibility
- **build**: Changes that affect the build system or external dependencies
- **ci**: Changes to our continuous integration processes or workflows
- **chore**: Refactor, cleanup, or other non-functional code changes
- **docs**: Documentation update or addition
- **feat**: Introduces a new feature or enhancement to the codebase
- **fix**: Bug fix or error correction
- **i18n**: Internationalization or localization changes
- **perf**: Performance improvement
- **refactor**: Code restructuring for better maintainability, readability, or scalability
- **style**: Changes that do not affect the meaning of the code (white space, formatting, missing semi-colons, etc.)
- **test**: Adding missing tests or correcting existing tests
- **WIP**: Work in progress, a temporary label for incomplete or ongoing work
# Changelog Entry
### Description
This PR will improve db performance, especisally sqlite, by:
- Enable `WAL` for sqlite. It will only work for sqlite.
- Reduce the update number of `user.last_active_at` to 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
- Add `DATABASE_ENABLE_SQLITE_WAL` option to enable SQLite WAL mode for better performance.
- Introduce a new decorator `deduplicate` in `backend/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 return `None`.
- Add `DATABASE_DEDUPLICATE_INTERVAL` configuration to control the deduplication interval (unit: second) for updating `user.last_active_at`.
### Breaking Changes
- If `DATABASE_ENABLE_SQLITE_WAL` is enabled, it will enable WAL mode for sqlite (default: disabled).
- If `DATABASE_DEDUPLICATE_INTERVAL` is not 0, `user.last_active_at` might not be accurate (default: 0).
---
### Screenshots or Videos
1. Before the improvements (or `DATABASE_ENABLE_SQLITE_WAL=false` and `DATABASE_DEDUPLICATE_INTERVAL=0`)
<img width="4724" height="2146" alt="图片" src="https://github.com/user-attachments/assets/6cb7162f-60d5-4472-8352-bfb36cae90a8" />
2. Only enable WAL (`DATABASE_ENABLE_SQLITE_WAL=true` and `DATABASE_DEDUPLICATE_INTERVAL=0`)
<img width="4722" height="1856" alt="图片" src="https://github.com/user-attachments/assets/fb3b5098-6b21-481c-88c3-7a0c81ebb243" />
3. Enable both (`DATABASE_ENABLE_SQLITE_WAL=true` and `DATABASE_DEDUPLICATE_INTERVAL=10`)
<img width="2379" height="578" alt="截屏2025-07-19 19 12 44" src="https://github.com/user-attachments/assets/c1ddb215-22aa-4698-8812-ab7d6e4a9e3d" />
<img width="2378" height="463" alt="截屏2025-07-19 19 13 16" src="https://github.com/user-attachments/assets/6bfa9ec2-ddf4-41f7-a524-0e2aec490259" />
(In the second picture, there is no `UPDATE` operation 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)](/CONTRIBUTOR_LICENSE_AGREEMENT), and I am providing my contributions under its terms.
---
<sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
📋 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.