perf: cache admin job lists + targeted polling for audio/translation pages
Some checks failed
Release / Test backend (push) Successful in 41s
Release / Check ui (push) Failing after 34s
Release / Upload source maps (push) Has been skipped
Release / Docker / ui (push) Has been skipped
Release / Docker / caddy (push) Successful in 40s
Release / Docker / runner (push) Has been cancelled
Release / Gitea Release (push) Has been cancelled
Release / Docker / backend (push) Has been cancelled

- Add 30s Valkey cache to listScrapingTasks, listAudioJobs, listTranslationJobs
  (use listN(500) instead of unbounded listAll to cap at one request)
- Delete listAudioCache() — derive AudioCacheEntry[] from jobs in server load
- Add listBookSlugs() with 10min cache — replaces full listBooks() in translation load
- Add GET /api/admin/audio-jobs, /api/admin/translation-jobs, /api/admin/scrape-tasks
  (lightweight polling endpoints backed by the Valkey cache)
- Replace invalidateAll() interval polling in audio+translation pages with
  targeted fetch to the new endpoints (avoids re-running full server load)
This commit is contained in:
root
2026-04-06 20:33:46 +05:00
parent 75e6a870d3
commit b6904bcb6e
8 changed files with 131 additions and 33 deletions

View File

@@ -0,0 +1,16 @@
import { json, error } from '@sveltejs/kit';
import type { RequestHandler } from './$types';
import { listAudioJobs } from '$lib/server/pocketbase';
/**
* GET /api/admin/audio-jobs
* Returns the current audio jobs list (served from 30 s Valkey cache).
* Used by the admin audio page for lightweight polling instead of invalidateAll().
*/
export const GET: RequestHandler = async ({ locals }) => {
if (!locals.user || locals.user.role !== 'admin') {
throw error(403, 'Forbidden');
}
const jobs = await listAudioJobs().catch(() => []);
return json({ jobs });
};

View File

@@ -0,0 +1,16 @@
import { json, error } from '@sveltejs/kit';
import type { RequestHandler } from './$types';
import { listScrapingTasks } from '$lib/server/pocketbase';
/**
* GET /api/admin/scrape-tasks
* Returns the current scraping task list (served from 30 s Valkey cache).
* Used by the admin scrape page for lightweight polling instead of invalidateAll().
*/
export const GET: RequestHandler = async ({ locals }) => {
if (!locals.user || locals.user.role !== 'admin') {
throw error(403, 'Forbidden');
}
const tasks = await listScrapingTasks().catch(() => []);
return json({ tasks });
};

View File

@@ -0,0 +1,16 @@
import { json, error } from '@sveltejs/kit';
import type { RequestHandler } from './$types';
import { listTranslationJobs } from '$lib/server/pocketbase';
/**
* GET /api/admin/translation-jobs
* Returns the current translation jobs list (served from 30 s Valkey cache).
* Used by the admin translation page for lightweight polling instead of invalidateAll().
*/
export const GET: RequestHandler = async ({ locals }) => {
if (!locals.user || locals.user.role !== 'admin') {
throw error(403, 'Forbidden');
}
const jobs = await listTranslationJobs().catch(() => []);
return json({ jobs });
};