mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[PR #5796] [CLOSED] perf(database): batch traffic writes #5989
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#5989
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/5796
Author: @rqzbeh
Created: 7/4/2026
Status: ❌ Closed
Base:
main← Head:perf/database-hardening-v2📝 Commits (3)
1c22269perf(database): batch traffic writescee5ef0fix(database): address traffic batching review414d1fbfix(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, targeted settings writes, and DB-specific indexes.
Includes review fixes from the closed PR: corrected SQLite bind-variable chunk sizing, restored legacy Telegram ID fallback for unmigrated inbound settings, and avoids the PostgreSQL
idx_clients_tg_idpartial-index conflict.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.
Replaces #5795.
Type of change
Areas affected
How was this tested?
go test ./internal/database ./internal/web/servicemake verifyNew/updated coverage:
internal/database/dialect_test.gointernal/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.