Fix library templates db syncing and pagination issues

This commit is contained in:
akhisud3195 2025-09-16 14:32:04 +04:00
parent 893ad87268
commit af3adc797f
6 changed files with 147 additions and 102 deletions

View file

@ -41,8 +41,15 @@ const CreateTemplateSchema = z.object({
export async function listAssistantTemplates(request: z.infer<typeof ListTemplatesSchema>) {
const user = await authCheck();
// Kick off best-effort library reconcile/seed on each UI fetch (non-blocking)
try { void ensureLibraryTemplatesSeeded(); } catch {}
// Throttle best-effort library reconcile/seed to avoid repeated bursts
try {
const last = (globalThis as any).__lastLibrarySeedAt as number | undefined;
const now = Date.now();
if (!last || now - last > 60_000) { // at most once per minute
(globalThis as any).__lastLibrarySeedAt = now;
void ensureLibraryTemplatesSeeded();
}
} catch {}
const params = ListTemplatesSchema.parse(request);