mirror of
https://github.com/saltbo/zpan.git
synced 2026-08-29 00:01:42 +08:00
9c16adbdc0
The admin quota listing called getEffectiveQuota per org, firing ~8 sequential queries each (N+1). On D1 every query is a network round-trip, so the endpoint scaled linearly with org count and risked the Workers subrequest cap. - Add getEffectiveQuotasByOrg: resolves every org in 2 queries (quota rows + active entitlements) and aggregates in memory. Route uses it. - Remove the inline traffic-period reset writes from the read paths (getEffectiveQuota and the listing route). getEffectiveQuota already normalizes a stale period in memory, so reads stay correct. - Add resetExpiredTrafficQuotas and run it on a new monthly cron (0 0 1 * *) for CF Workers and a daily idempotent interval for Node. The consume write path keeps its atomic reset-and-consume as a self-healing fallback if a scheduled run is missed. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>