mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[PR #5800] [CLOSED] perf(database): batch traffic writes #5993
Labels
No labels
backlog
bug
clarification needed
documentation
duplicate
enhancement
github_actions
good first issue
invalid
javascript
New Feature
PR welcomed
pull-request
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
MHSanaei/3x-ui#5993
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
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/MHSanaei/3x-ui/pull/5800
Author: @rqzbeh
Created: 7/4/2026
Status: ❌ Closed
Base:
main← Head:perf/database-hardening-v4📝 Commits (4)
ac2a366perf(database): batch traffic writesb310352fix(database): address traffic batching review8754733fix(database): make WAL backups and PG batches safe1309718fix(database): address WAL review followups📊 Changes
16 files changed (+864 additions, -140 deletions)
View changed files
📝
.gitignore(+1 -1)📝
README.md(+2 -0)📝
docs/architecture.md(+4 -1)📝
install.sh(+17 -6)📝
internal/database/db.go(+145 -9)📝
internal/database/db_settled_test.go(+68 -0)📝
internal/database/dialect.go(+202 -1)➕
internal/database/dialect_test.go(+177 -0)📝
internal/web/service/client_bulk.go(+3 -3)📝
internal/web/service/client_groups.go(+2 -2)📝
internal/web/service/client_inbound_apply.go(+4 -4)📝
internal/web/service/client_lookup.go(+11 -3)📝
internal/web/service/inbound_client_traffic_test.go(+41 -0)📝
internal/web/service/inbound_node.go(+4 -2)📝
internal/web/service/inbound_traffic.go(+181 -106)📝
internal/web/service/server.go(+2 -2)📄 Description
Summary
Optimizes database hot paths for traffic accounting and client lookups across SQLite and PostgreSQL. Adds SQLite WAL mode, dialect-aware batch updates, shorter traffic transactions, WAL-safe backups, targeted settings writes, DB-specific indexes, and etckeeper ignores for SQLite WAL sidecars.
This is a fresh PR replacing closed PRs #5795, #5796, and #5798. It includes the latest review follow-ups from #5798.
Why
Traffic polling currently grows into many per-client updates and keeps slow renew/disable work in the same write transaction. JSON LIKE scans also bypass indexed client columns. This lowers lock time and query cost as client count grows while keeping legacy data readable and raw SQLite backups complete under WAL.
Type of change
Areas affected
How was this tested?
go test ./internal/database ./internal/web/service(464 tests)PATH="$HOME/go/bin:$PATH" make verifyNew/updated coverage:
internal/database/dialect_test.gointernal/database/dialect_test.gowhenXUI_DB_TYPE=postgresandXUI_DB_DSNare set.dbcheckpoint backup safety, and post-migrate remark/tg_id index creation ininternal/database/db_settled_test.gotgIdlookup fallback ininternal/web/service/inbound_client_traffic_test.goPostgreSQL live tests were not run locally because no
XUI_DB_TYPE=postgres+XUI_DB_DSNwas configured.Screenshots / recordings
N/A
Breaking changes
None.
Checklist
go build ./...and the test suite pass locally.npm run lint,npm run typecheck, andnpm run buildpass.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.