refactor(actions): 优化 AI改进代码中的数据库查询

- 移除了不必要的 PrismaClient 实例化
- 更新了 problemId 字段的使用,使其与数据库结构保持一致
This commit is contained in:
fly6516 2025-05-16 10:14:28 +08:00
parent a89864e70e
commit c8586c671c

View File

@ -7,8 +7,7 @@ import {
} from "@/types/ai-improve"; } from "@/types/ai-improve";
import { openai } from "@/lib/ai"; import { openai } from "@/lib/ai";
import { CoreMessage, generateText } from "ai"; import { CoreMessage, generateText } from "ai";
import { PrismaClient } from '@/generated/client'; import prisma from '@/generated/client';
const prisma = new PrismaClient();
/** /**
* AI优化代码 * AI优化代码
@ -25,7 +24,7 @@ export const optimizeCode = async (
if (input.problemId) { if (input.problemId) {
try { try {
const problem = await prisma.problem.findUnique({ const problem = await prisma.problem.findUnique({
where: { problemId: input.problemId }, where: { id: input.problemId },
}); });
if (problem) { if (problem) {
problemDetails = ` problemDetails = `