3x-ui/internal/web/controller
mrchatam 33a469315a
feat(clients): preserve traffic counters in portable export/import (#6469)
* feat(clients): preserve traffic counters in portable export/import

ExportAll now attaches client_traffics up/down (plus resetCount and
last-seen fields) on each portable payload, and ImportClients restores
them only for newly created emails so skipped/existing clients keep
their live counters. Fixes #5858.

* fix(clients): restore imported traffic only onto rows the import created

Review of the portable-traffic export/import (#5858) found four defects:

- An orphan's restored row was hand-built, dropping reset_weekday and
  forcing enable=true; a row kept by a keepTraffic delete kept the old
  client's limits. depletedClientsClause then matched a weekly-renewing
  over-quota orphan and DelDepleted deleted it. Orphan rows now go
  through AddClientStat, whose upsert refreshes config and keeps counters,
  so the unused traffic.total field is dropped from the export.
- Created clients were inferred from Skipped emails, so a duplicate email
  in the file left the created copy with zero counters. bulkCreate now
  reports which payloads inserted a record, and only those are restored.
- Each client took its own serialized-writer commit: 2000 clients spent
  3.66s instead of 0.52s. Counters now apply in batched transactions
  (0.51s).
- importClients discarded needRestart when the late restore step failed
  after clients were committed; it now flags and notifies first, as
  create already does.

The /clients/export and /clients/import API docs now describe traffic.

* fix(groups): keep imported traffic out of group totals

Group totals keep a deleted client's usage (#5675), and the portable
import restores that same usage onto the re-created client. Export,
delete, re-import therefore counted it twice in ListGroups, and a fresh
panel showed the migrated usage as consumption of its groups.

Restored counters are usage from before the import, so the import now
shifts each group's baseline up by what it restored, in the same
transaction. A group total no longer moves at import time; only traffic
consumed afterwards counts. The baseline shift reuses the #5675 helper,
now signed.

---------

Co-authored-by: Sanaei <ho3ein.sanaei@gmail.com>
2026-09-27 02:48:40 +02:00
..
api.go fix(api): return 401 for invalid Bearer token instead of 404 (#6459) 2026-09-12 11:52:15 +02:00
api_auth_test.go fix(api): return 401 for invalid Bearer token instead of 404 (#6459) 2026-09-12 11:52:15 +02:00
base.go
client.go feat(clients): preserve traffic counters in portable export/import (#6469) 2026-09-27 02:48:40 +02:00
client_happ_test.go feat(happ): generate Crypt5 subscription links locally (#6494) 2026-09-13 12:44:55 +02:00
client_partial_apply_test.go feat(clients): preserve traffic counters in portable export/import (#6469) 2026-09-27 02:48:40 +02:00
client_renewal_preview_test.go feat(clients): add calendar weekly renewal and schedule previews (#6524) 2026-09-26 22:59:23 +02:00
dist.go feat(web): add network-only PWA installability (#6190) 2026-08-18 15:33:20 +02:00
dist_test.go feat(web): add network-only PWA installability (#6190) 2026-08-18 15:33:20 +02:00
geodata_test.go feat(xray): browse geosite/geoip categories from routing rules (#6165) 2026-08-15 17:12:59 +02:00
group.go fix(groups): report changed bulk moves without restarting xray (#6199) 2026-08-14 19:50:06 +02:00
host.go feat(hosts): bulk-add multiple hosts to multiple inbounds (#5677) 2026-07-08 23:35:20 +02:00
host_test.go feat(hosts): bulk-add multiple hosts to multiple inbounds (#5677) 2026-07-08 23:35:20 +02:00
import_db_restart_test.go fix(web): restart panel after ImportDB so subPath routes match (#6446) (#6456) 2026-09-13 21:39:15 +02:00
inbound.go fix(sub): never use X-Real-IP as the subscription host (#6608) 2026-09-26 21:13:46 +02:00
inbound_node_sync_test.go fix(inbounds): reject missing TLS certificates before saving (#6429) 2026-09-08 18:08:24 +02:00
index.go feat(panel): add sponsor slots fed from sponsors.sanaei.dev 2026-09-26 03:31:51 +02:00
login_limiter.go Repo-wide self-correcting audit: 54 verified bug fixes (#5970) 2026-07-17 00:33:06 +02:00
login_limiter_test.go chore: refresh dependencies, fix Linux tool tasks, modernize Go idioms 2026-07-25 16:08:09 +02:00
node.go fix(nodes): apply a rotated master mTLS certificate without restarting the panel (#6194) 2026-08-15 16:03:42 +02:00
node_credentials_writeonly_test.go fix(nodes): report probe heartbeat persistence failures (#6207) 2026-08-13 12:34:37 +02:00
panel_update_test.go fix: make all self-managed file downloads/installs atomic, with real completion status (#5711) 2026-07-02 18:19:33 +02:00
pwa.go feat(web): add network-only PWA installability (#6190) 2026-08-18 15:33:20 +02:00
pwa_test.go feat(web): add network-only PWA installability (#6190) 2026-08-18 15:33:20 +02:00
server.go fix(nodes): stop a restarting panel from reporting itself as down 2026-09-18 13:25:24 +03:00
setting.go feat(discord): add Discord notification bot service (#6486) 2026-09-13 14:04:53 +02:00
setting_test.go feat(discord): add Discord notification bot service (#6486) 2026-09-13 14:04:53 +02:00
spa.go refactor(frontend): replace axios with the native Fetch API 2026-07-08 01:09:18 +02:00
spa_test.go fix(web): serve panel SPA routes from NoRoute (#5536) 2026-06-24 21:19:12 +02:00
sub_balancer.go feat(sub): leastLoad member weights for subscription balancers (#6304) 2026-09-02 20:21:27 +02:00
sub_balancer_test.go feat(sub): client-side balancers for the JSON subscription (#6243) 2026-08-23 22:34:20 +02:00
util.go fix(sub): honor trustedProxyCIDRs before forwarded URLs (#6135) 2026-07-29 21:01:59 +02:00
util_test.go fix(sub): never use X-Real-IP as the subscription host (#6608) 2026-09-26 21:13:46 +02:00
websocket.go
xray_setting.go feat(geodata): add standard source presets (#6504) 2026-09-13 20:02:43 +02:00
xray_setting_warp_test.go fix(warp): surface update-clock persistence failures (#6209) 2026-08-13 12:31:05 +02:00