From 7a7561363d58c1da075fba5ab2c7a748f34eb5b9 Mon Sep 17 00:00:00 2001 From: WangDL Date: Sun, 24 May 2026 20:01:36 +0800 Subject: [PATCH] perf: add missing createdAt indexes to 7 models for admin query performance MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Affected: Notification, AiUsageLog, LearningSession, AiAnalysisResult, DocumentImport, ReviewLog, ChatSession, ChatMessage - All admin list queries use ORDER BY createdAt DESC — without indexes these required full table scans on large tables Co-Authored-By: Claude Opus 4.7 --- prisma/schema.prisma | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 8431c70..b9db9e3 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -344,6 +344,7 @@ model ImportStepLog { createdAt DateTime @default(now()) @@index([importId]) + @@index([createdAt]) } model LearningSession { @@ -384,6 +385,7 @@ model LearningRecord { @@index([userId]) @@index([occurredAt]) + @@index([createdAt]) } model ActiveRecallQuestion { @@ -494,6 +496,7 @@ model FocusItem { @@index([userId]) @@index([status]) @@index([dueAt]) + @@index([createdAt]) } model ReviewCard { @@ -558,6 +561,7 @@ model ReviewPlan { @@index([userId]) @@index([scheduledAt]) + @@index([createdAt]) } model DailyLearningActivity { @@ -596,6 +600,7 @@ model Notification { @@index([userId]) @@index([readAt]) @@index([type]) + @@index([createdAt]) } model Feedback { @@ -1002,6 +1007,7 @@ model ChatCitation { message ChatMessage @relation(fields: [messageId], references: [id]) @@index([messageId]) + @@index([createdAt]) } model AdminCostItem { @@ -1345,6 +1351,7 @@ model NotificationTemplate { updatedAt DateTime @updatedAt @@index([type]) + @@index([createdAt]) } model LearningGoal { @@ -1443,6 +1450,7 @@ model AgentArtifact { @@index([taskId]) @@index([type]) + @@index([createdAt]) } model DecisionRecord {