mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[PR #5798] [CLOSED] perf(database): batch traffic writes #5990
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#5990
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/5798
Author: @rqzbeh
Created: 7/4/2026
Status: ❌ Closed
Base:
main← Head:perf/database-hardening-v3📝 Commits (3)
e78c23bperf(database): batch traffic writes227f1f8fix(database): address traffic batching review7f394fafix(database): make WAL backups and PG batches safe📊 Changes
15 files changed (+751 additions, -134 deletions)
View changed files
📝
.gitignore(+1 -1)📝
README.md(+2 -0)📝
docs/architecture.md(+4 -1)📝
internal/database/db.go(+140 -9)📝
internal/database/db_settled_test.go(+68 -0)📝
internal/database/dialect.go(+202 -1)➕
internal/database/dialect_test.go(+86 -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, and DB-specific indexes.
This is a fresh PR replacing closed PRs #5795 and #5796.
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/servicemake verifyNew/updated coverage:
internal/database/dialect_test.go.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.