mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 19:11:53 +07:00
[PR #5795] [CLOSED] perf(database): batch traffic writes #5988
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#5988
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/5795
Author: @rqzbeh
Created: 7/4/2026
Status: ❌ Closed
Base:
main← Head:perf/database-hardening📝 Commits (2)
b34f286perf(database): batch traffic writese14691cPotential fix for pull request finding📊 Changes
14 files changed (+477 additions, -133 deletions)
View changed files
📝
.gitignore(+1 -1)📝
docs/architecture.md(+2 -1)📝
internal/database/db.go(+40 -6)📝
internal/database/db_settled_test.go(+22 -0)📝
internal/database/dialect.go(+165 -1)➕
internal/database/dialect_test.go(+71 -0)📝
internal/database/index_tags_test.go(+1 -0)📝
internal/database/model/model.go(+1 -1)📝
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_node.go(+4 -2)📝
internal/web/service/inbound_traffic.go(+150 -109)📄 Description
Summary
Optimizes database hot paths for traffic accounting and client lookups across SQLite and PostgreSQL. Adds WAL mode for SQLite, dialect-aware batch updates, narrower transactions, targeted settings writes, and DB-specific indexes.
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.
Type of change
Areas affected
How was this tested?
go test ./internal/database ./internal/web/servicemake testmake verifyNew coverage:
internal/database/dialect_test.gointernal/database/db_settled_test.gointernal/database/index_tags_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.