mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-09-24 16:05:44 +08:00
Replace the stale Redis cache read + invalidation hack with direct DB transaction RETURNING values: - deductUsageBillingBalance: add RETURNING balance to get post-deduction balance - incrementUsageBillingAccountQuota: extend RETURNING to include all 6 quota dimensions (daily/weekly/total used+limit) - Expand UsageBillingApplyResult with NewBalance and QuotaState fields - finalizePostUsageBilling uses result directly, no Redis read needed - CheckAccountQuotaAfterIncrement accepts optional QuotaState to skip fetchFreshAccount when DB values are available This eliminates the race condition where QueueDeductBalance async update hadn't propagated to Redis before GetUserBalance read, causing oldBalance to be inflated and threshold crossing detection to always fail.