feat: 优化接口速度

This commit is contained in:
2026-04-24 22:02:53 +08:00
parent fd20a4411b
commit d1c5b818d9
5 changed files with 148 additions and 60 deletions
+34 -20
View File
@@ -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 })