quick to query
This commit is contained in:
parent
9b6b5cdda9
commit
fb2fb08eae
@ -284,6 +284,9 @@ model SimulatorRun {
|
|||||||
promptVersion PromptVersion? @relation(fields: [promptVersionId], references: [id], onDelete: SetNull)
|
promptVersion PromptVersion? @relation(fields: [promptVersionId], references: [id], onDelete: SetNull)
|
||||||
model Model @relation(fields: [modelId], references: [id])
|
model Model @relation(fields: [modelId], references: [id])
|
||||||
|
|
||||||
|
// 添加索引优化查询性能
|
||||||
|
@@index([userId, createdAt(sort: Desc)])
|
||||||
|
@@index([userId, status, createdAt(sort: Desc)])
|
||||||
@@map("simulator_runs")
|
@@map("simulator_runs")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,11 +95,9 @@ export async function GET(request: NextRequest) {
|
|||||||
output: true,
|
output: true,
|
||||||
error: true,
|
error: true,
|
||||||
createdAt: true,
|
createdAt: true,
|
||||||
completedAt: true,
|
|
||||||
inputTokens: true,
|
inputTokens: true,
|
||||||
outputTokens: true,
|
outputTokens: true,
|
||||||
totalCost: true,
|
totalCost: true,
|
||||||
duration: true,
|
|
||||||
prompt: {
|
prompt: {
|
||||||
select: { id: true, name: true }
|
select: { id: true, name: true }
|
||||||
},
|
},
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
'use client'
|
'use client'
|
||||||
|
|
||||||
import { useState, useEffect, useCallback } from 'react'
|
import { useState, useEffect, useCallback, useMemo } from 'react'
|
||||||
import { useTranslations } from 'next-intl'
|
import { useTranslations } from 'next-intl'
|
||||||
import { useAuthUser } from '@/hooks/useAuthUser'
|
import { useAuthUser } from '@/hooks/useAuthUser'
|
||||||
import { Header } from '@/components/layout/Header'
|
import { Header } from '@/components/layout/Header'
|
||||||
@ -160,7 +160,7 @@ export default function SimulatorPage() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const getRunStats = () => {
|
const stats = useMemo(() => {
|
||||||
const total = runs.length
|
const total = runs.length
|
||||||
const completed = runs.filter(run => run.status === 'completed').length
|
const completed = runs.filter(run => run.status === 'completed').length
|
||||||
const running = runs.filter(run => run.status === 'running').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)
|
const totalCost = runs.reduce((sum, run) => sum + (run.totalCost || 0), 0)
|
||||||
|
|
||||||
return { total, completed, running, failed, totalTokens, totalCost }
|
return { total, completed, running, failed, totalTokens, totalCost }
|
||||||
}
|
}, [runs])
|
||||||
|
|
||||||
if (authLoading) {
|
if (authLoading) {
|
||||||
return (
|
return (
|
||||||
@ -190,7 +190,6 @@ export default function SimulatorPage() {
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
const stats = getRunStats()
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="min-h-screen">
|
<div className="min-h-screen">
|
||||||
|
Loading…
Reference in New Issue
Block a user