(workspaceId: string, limits: TablePlanLimits)
| 149 | } |
| 150 | |
| 151 | function cacheLimits(workspaceId: string, limits: TablePlanLimits): void { |
| 152 | // Keep the Map bounded for a new key: sweep expired entries, then (if a burst of |
| 153 | // all-fresh entries still sits at the cap) evict oldest-inserted ones. Map iteration |
| 154 | // is insertion order, so the first key is the oldest. Net: size never exceeds the cap. |
| 155 | if (limitsCache.size >= LIMITS_CACHE_MAX_ENTRIES && !limitsCache.has(workspaceId)) { |
| 156 | const now = Date.now() |
| 157 | for (const [key, entry] of limitsCache) { |
| 158 | if (entry.expiresAt <= now) limitsCache.delete(key) |
| 159 | } |
| 160 | while (limitsCache.size >= LIMITS_CACHE_MAX_ENTRIES) { |
| 161 | const oldest = limitsCache.keys().next().value |
| 162 | if (oldest === undefined) break |
| 163 | limitsCache.delete(oldest) |
| 164 | } |
| 165 | } |
| 166 | limitsCache.set(workspaceId, { limits, expiresAt: Date.now() + LIMITS_CACHE_TTL_MS }) |
| 167 | } |
| 168 | |
| 169 | /** |
| 170 | * Thrown by {@link assertRowCapacity} when a write would exceed the workspace's |
no test coverage detected