quick to query

This commit is contained in:
songtianlun 2025-09-01 23:21:08 +08:00
parent 9b6b5cdda9
commit fb2fb08eae
3 changed files with 6 additions and 6 deletions

View File

@ -284,6 +284,9 @@ model SimulatorRun {
promptVersion PromptVersion? @relation(fields: [promptVersionId], references: [id], onDelete: SetNull)
model Model @relation(fields: [modelId], references: [id])
// 添加索引优化查询性能
@@index([userId, createdAt(sort: Desc)])
@@index([userId, status, createdAt(sort: Desc)])
@@map("simulator_runs")
}

View File

@ -95,11 +95,9 @@ export async function GET(request: NextRequest) {
output: true,
error: true,
createdAt: true,
completedAt: true,
inputTokens: true,
outputTokens: true,
totalCost: true,
duration: true,
prompt: {
select: { id: true, name: true }
},

View File

@ -1,6 +1,6 @@
'use client'
import { useState, useEffect, useCallback } from 'react'
import { useState, useEffect, useCallback, useMemo } from 'react'
import { useTranslations } from 'next-intl'
import { useAuthUser } from '@/hooks/useAuthUser'
import { Header } from '@/components/layout/Header'
@ -160,7 +160,7 @@ export default function SimulatorPage() {
}
}
const getRunStats = () => {
const stats = useMemo(() => {
const total = runs.length
const completed = runs.filter(run => run.status === 'completed').length
const running = runs.filter(run => run.status === 'running').length
@ -173,7 +173,7 @@ export default function SimulatorPage() {
const totalCost = runs.reduce((sum, run) => sum + (run.totalCost || 0), 0)
return { total, completed, running, failed, totalTokens, totalCost }
}
}, [runs])
if (authLoading) {
return (
@ -190,7 +190,6 @@ export default function SimulatorPage() {
return null
}
const stats = getRunStats()
return (
<div className="min-h-screen">