Improve latency of the job list endpoint

This commit is contained in:
Jaret Burkett
2026-07-04 13:22:09 -06:00
parent 3a94591c89
commit 6c0d1c4679
2 changed files with 30 additions and 7 deletions

View File

@@ -9,6 +9,7 @@ export async function GET(request: Request) {
const id = searchParams.get('id');
const job_ref = searchParams.get('job_ref');
const job_type = searchParams.get('job_type');
const only_active = searchParams.get('only_active');
try {
if (id) {
@@ -25,8 +26,16 @@ export async function GET(request: Request) {
return NextResponse.json(job);
}
const where: any = {};
if (job_type) {
where.job_type = job_type;
}
if (only_active === 'true') {
where.status = { in: ['running', 'queued', 'stopping'] };
}
const jobs = await prisma.job.findMany({
where: job_type ? { job_type } : undefined,
where,
orderBy: { created_at: 'desc' },
});
return NextResponse.json({ jobs: jobs });