Add database cleanup for stale data
Some checks failed
Build & Deploy to Staging / Build & Deploy to Staging (push) Has been cancelled
Some checks failed
Build & Deploy to Staging / Build & Deploy to Staging (push) Has been cancelled
- Add cleanupStaleData() function in db.ts - Deletes expired pending_verifications - Deletes unverified free-tier API keys - Deletes orphaned usage rows - Logs cleanup counts and returns results - Add POST /v1/admin/cleanup endpoint (admin auth required) - Run cleanup automatically 30s after startup (non-blocking)
This commit is contained in:
parent
f17b483682
commit
1623813c56
2 changed files with 17 additions and 0 deletions
10
src/index.ts
10
src/index.ts
|
|
@ -355,6 +355,16 @@ async function start() {
|
|||
logger.info(`Loaded ${getAllKeys().length} API keys`);
|
||||
const server = app.listen(PORT, () => logger.info(`DocFast API running on :${PORT}`));
|
||||
|
||||
// Run database cleanup 30 seconds after startup (non-blocking)
|
||||
setTimeout(async () => {
|
||||
try {
|
||||
logger.info("Running scheduled database cleanup...");
|
||||
await cleanupStaleData();
|
||||
} catch (err) {
|
||||
logger.error({ err }, "Startup cleanup failed (non-fatal)");
|
||||
}
|
||||
}, 30_000);
|
||||
|
||||
let shuttingDown = false;
|
||||
const shutdown = async (signal: string) => {
|
||||
if (shuttingDown) return;
|
||||
|
|
|
|||
|
|
@ -7,6 +7,13 @@ interface RateLimitEntry {
|
|||
resetTime: number;
|
||||
}
|
||||
|
||||
interface RateLimitResult {
|
||||
allowed: boolean;
|
||||
limit: number;
|
||||
remaining: number;
|
||||
resetTime: number; // Unix timestamp in milliseconds
|
||||
}
|
||||
|
||||
// Per-key rate limits (requests per minute)
|
||||
const FREE_RATE_LIMIT = 10;
|
||||
const PRO_RATE_LIMIT = 30;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue