feat: 添加分页功能和缓存管理,优化问答记录展示
This commit is contained in:
+11
-4
@@ -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 };
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user