feat: 添加分页功能和缓存管理,优化问答记录展示

This commit is contained in:
2026-05-23 00:44:47 +08:00
parent c48d57df14
commit cc7125e681
16 changed files with 172 additions and 243 deletions
+11 -4
View File
@@ -1,16 +1,23 @@
// server/api/stats.get.ts - 服务运行统计接口
import { prisma } from "~~/server/utils/db";
import { createApiLogger } from "~~/server/utils/logging";
import { getRuntimeStats } from "~~/server/utils/runtimeState";
/**
* 运行统计接口
*
* 统计信息包含 uptime、模型名、缓存数量、最近问答记录数
* 返回进程 uptime、模型名以及当前用户的问答记录
* 必须携带有效 session cookie(由 api-auth middleware 统一鉴权)
*/
export default defineEventHandler((event) => {
export default defineEventHandler(async (event) => {
const logger = createApiLogger(event, "api.stats");
// getRuntimeStats 会实时清理过期缓存,再返回有效缓存数量
const userId = event.context.auth!.user.id;
const [runtimeStats, qa_records_count] = await Promise.all([
Promise.resolve(getRuntimeStats()),
prisma.qaRecord.count({ where: { userId } })
]);
logger.info("finish_success");
return getRuntimeStats();
return { ...runtimeStats, qa_records_count };
});