Improve latency of the job list endpoint
This commit is contained in:
@@ -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 });
|
||||
|
||||
Reference in New Issue
Block a user