refactor: optimize cron scheduling, DB maintenance, and TMDB reliability

- Skip recommendations refresh for titles fetched within the last 7 days via `getTitlesWithFreshRecommendations`; only stale titles are re-fetched
- Replace `Promise.allSettled` in `refreshTvChildren` with a `mapWithConcurrency` helper (concurrency = 5) to stay within TMDB's rate limit
- Add 30s request timeout middleware to TMDB client to prevent indefinitely hung fetches
- Expand `optimizeDb` weekly job to prune 30-day-old cron runs, integration events, expired sessions, and expired verifications
- Add `wal_checkpoint(TRUNCATE)` to `optimizeDatabase` so the WAL is flushed before `PRAGMA optimize`
- Add `recoverStaleImportJobs` called on server startup to mark any `pending`/`running` import jobs as errored after a crash/restart
- Return `false` from `triggerJob` immediately if the job is already running
This commit is contained in:
2026-03-23 13:59:31 -04:00
parent d9be566863
commit b289b7abed
17 changed files with 235 additions and 36 deletions
+5 -5
View File
@@ -3,15 +3,15 @@
"version": "0.0.0",
"private": true,
"scripts": {
"build": "next build",
"dev": "next dev",
"start": "next start",
"build": "bun --bun next build",
"dev": "bun --bun next dev",
"start": "bun --bun next start",
"lint": "oxlint",
"format": "oxfmt",
"format:check": "oxfmt --check",
"check-types": "fumadocs-mdx && next typegen && tsc --noEmit",
"check-types": "bun --bun fumadocs-mdx && bun --bun next typegen && tsc --noEmit",
"generate:api-docs": "bun scripts/generate-api-docs.ts",
"postinstall": "fumadocs-mdx"
"postinstall": "bun --bun fumadocs-mdx"
},
"dependencies": {
"@takumi-rs/image-response": "^0.73.1",