From 7a3d94ed033e7c9d8c64ae89326f01f5bbd40e62 Mon Sep 17 00:00:00 2001 From: Jaret Burkett Date: Thu, 16 Jul 2026 16:51:05 -0600 Subject: [PATCH] Add caching to active job pull --- ui/src/app/api/jobs/route.ts | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/ui/src/app/api/jobs/route.ts b/ui/src/app/api/jobs/route.ts index 2db8f42..2077846 100644 --- a/ui/src/app/api/jobs/route.ts +++ b/ui/src/app/api/jobs/route.ts @@ -1,6 +1,7 @@ import { NextResponse } from 'next/server'; import { PrismaClient } from '@prisma/client'; import { isMac } from '@/helpers/basic'; +import { cached } from '@/server/apiCache'; const prisma = new PrismaClient(); @@ -32,6 +33,17 @@ export async function GET(request: Request) { } if (only_active === 'true') { where.status = { in: ['running', 'queued', 'stopping'] }; + const jobs = await cached( + 'jobs-active', + () => + prisma.job.findMany({ + where, + orderBy: { created_at: 'desc' }, + }), + 5000, + { job_type }, + ); + return NextResponse.json({ jobs: jobs }); } const jobs = await prisma.job.findMany({ @@ -52,16 +64,16 @@ export async function POST(request: Request) { let gpu_ids: string = body.gpu_ids; if (isMac()) { - gpu_ids = "mps"; + gpu_ids = 'mps'; } const extra: any = {}; - if ("job_ref" in body) { - extra["job_ref"] = body.job_ref; + if ('job_ref' in body) { + extra['job_ref'] = body.job_ref; } - if ("job_type" in body) { - extra["job_type"] = body.job_type; + if ('job_type' in body) { + extra['job_type'] = body.job_type; } if (id) {