()
| 15 | // Periodic cleanup of expired rows (runs once, shared across all stores) |
| 16 | let cleanupStarted = false; |
| 17 | function startCleanup(): void { |
| 18 | if (cleanupStarted) return; |
| 19 | cleanupStarted = true; |
| 20 | const timer = setInterval(async () => { |
| 21 | if (!isDatabaseInitialized()) return; |
| 22 | try { |
| 23 | await query(`DELETE FROM rate_limit_hits WHERE reset_at <= NOW()`); |
| 24 | } catch (err) { |
| 25 | logger.warn({ err }, 'Failed to clean up expired rate limit hits'); |
| 26 | } |
| 27 | }, 5 * 60 * 1000); // every 5 minutes |
| 28 | timer.unref(); |
| 29 | } |
| 30 | |
| 31 | export class PostgresStore implements Store { |
| 32 | private windowMs = 60_000; |
no test coverage detected