mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-08-31 23:47:14 +00:00
fix(postgres): record client traffic when inbound_id is stale
When an inbound is deleted and recreated it gets a new id, but the shared-by-email client_traffics row keeps the old (now deleted) inbound_id because AddClientStat's OnConflict-DoNothing never refreshes it. The traffic updater matched rows with inbound_id IN (local inbounds), so those orphaned rows were dropped: client traffic and online status stopped updating and auto-renew skipped them, while inbound-level traffic (matched by tag) kept working and the client count still showed (matched by email). Match by email and exclude only rows owned by a node inbound (inbound_id NOT IN (node inbounds)) in addClientTraffic and autoRenewClients. The local Xray only reports local-client emails, so a stale local pointer no longer hides the row, while genuine node-owned rows stay protected. Verified against a real affected dump: visible rows went from 4/668 to 668/668.
This commit is contained in:
@@ -1754,8 +1754,8 @@ func (s *InboundService) addClientTraffic(tx *gorm.DB, traffics []*xray.ClientTr
|
||||
}
|
||||
dbClientTraffics := make([]*xray.ClientTraffic, 0, len(traffics))
|
||||
err = tx.Model(xray.ClientTraffic{}).
|
||||
Where("email IN (?) AND inbound_id IN (?)", emails,
|
||||
tx.Model(&model.Inbound{}).Select("id").Where("node_id IS NULL")).
|
||||
Where("email IN (?) AND inbound_id NOT IN (?)", emails,
|
||||
tx.Model(&model.Inbound{}).Select("id").Where("node_id IS NOT NULL")).
|
||||
Find(&dbClientTraffics).Error
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -1882,7 +1882,7 @@ func (s *InboundService) autoRenewClients(tx *gorm.DB) (bool, int64, error) {
|
||||
|
||||
err = tx.Model(xray.ClientTraffic{}).
|
||||
Where("reset > 0 and expiry_time > 0 and expiry_time <= ?", now).
|
||||
Where("inbound_id IN (?)", tx.Model(&model.Inbound{}).Select("id").Where("node_id IS NULL")).
|
||||
Where("inbound_id NOT IN (?)", tx.Model(&model.Inbound{}).Select("id").Where("node_id IS NOT NULL")).
|
||||
Find(&traffics).Error
|
||||
if err != nil {
|
||||
return false, 0, err
|
||||
|
||||
Reference in New Issue
Block a user