fix(traffic): restore quota-disabled inbounds when their traffic is reset (#6962)

An inbound switched off by its own traffic cap came back on the periodic reset, but the admin per-inbound reset and Reset All Traffic only zeroed the counters. After that nothing could tell it from a hand-disabled inbound, so it stayed off with every client on it. Both admin resets now re-enable the inbounds their cap switched off, using the predicate the periodic job used, now in the service next to disableInvalidInbounds; expired and hand-disabled inbounds stay off.
This commit is contained in:
25f2002654
2026-11-02 20:20:25 +05:30
committed by GitHub
parent 1796352600
commit eae4725d99
9 changed files with 184 additions and 38 deletions
+24
View File
@@ -35,6 +35,30 @@ func (s *InboundService) disableInvalidInbounds(tx *gorm.DB, mutationBatch *traf
return false, count, err
}
// quotaDisabledInboundCond matches local inbounds their own cap switched off (args: enable, nowMs);
// expired or hand-disabled ones never match, so a reset cannot bring them back.
const quotaDisabledInboundCond = `enable = ? AND node_id IS NULL AND total > 0 AND up + down >= total AND (expiry_time <= 0 OR expiry_time > ?)`
// quotaDisabledInboundIDs lists the inbounds a traffic cap switched off.
func quotaDisabledInboundIDs(db *gorm.DB, nowMs int64) ([]int, error) {
var ids []int
err := db.Model(model.Inbound{}).
Where("user_id > ?", 0).
Where(quotaDisabledInboundCond, false, nowMs).
Pluck("id", &ids).Error
return ids, err
}
// quotaDisabledInbound reports whether a traffic cap switched this inbound off.
func quotaDisabledInbound(db *gorm.DB, id int, nowMs int64) (bool, error) {
var count int64
err := db.Model(model.Inbound{}).
Where("id = ?", id).
Where(quotaDisabledInboundCond, false, nowMs).
Count(&count).Error
return count > 0, err
}
const globalTrafficFreshWindow = 24 * time.Hour
func globalTrafficFreshSince(now time.Time) int64 {