feat: 优化接口速度
This commit is contained in:
@@ -218,26 +218,40 @@ async function handleGetScreenshots(req: NextRequest) {
|
||||
if (endTime) whereClause.timestamp.lte = endTime
|
||||
}
|
||||
|
||||
// Get records
|
||||
const records = await prisma.record.findMany({
|
||||
where: whereClause,
|
||||
include: {
|
||||
windows: true,
|
||||
screenshots: true
|
||||
},
|
||||
orderBy: {
|
||||
timestamp: 'desc'
|
||||
}
|
||||
})
|
||||
|
||||
// Get host info
|
||||
const host = await prisma.host.findUnique({
|
||||
where: { hostname },
|
||||
select: {
|
||||
hostname: true,
|
||||
lastUpdate: true
|
||||
}
|
||||
})
|
||||
const [records, host] = await Promise.all([
|
||||
prisma.record.findMany({
|
||||
where: whereClause,
|
||||
select: {
|
||||
id: true,
|
||||
timestamp: true,
|
||||
isStarred: true,
|
||||
windows: {
|
||||
select: {
|
||||
title: true,
|
||||
path: true,
|
||||
memory: true
|
||||
}
|
||||
},
|
||||
screenshots: {
|
||||
select: {
|
||||
fileId: true,
|
||||
filename: true,
|
||||
monitorName: true
|
||||
}
|
||||
}
|
||||
},
|
||||
orderBy: {
|
||||
timestamp: 'asc'
|
||||
}
|
||||
}),
|
||||
prisma.host.findUnique({
|
||||
where: { hostname },
|
||||
select: {
|
||||
hostname: true,
|
||||
lastUpdate: true
|
||||
}
|
||||
})
|
||||
])
|
||||
|
||||
if (!host) {
|
||||
return NextResponse.json({ error: '未找到主机记录' }, { status: 404 })
|
||||
|
||||
Reference in New Issue
Block a user