diff --git a/prisma/migrations/20240109123840_add_monitor_data_created_at_index/migration.sql b/prisma/migrations/20240109123840_add_monitor_data_created_at_index/migration.sql new file mode 100644 index 0000000..2e4357d --- /dev/null +++ b/prisma/migrations/20240109123840_add_monitor_data_created_at_index/migration.sql @@ -0,0 +1,2 @@ +-- CreateIndex +CREATE INDEX "MonitorData_createdAt_idx" ON "MonitorData"("createdAt"); diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 9d4ec63..5ff5da2 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -292,6 +292,8 @@ model MonitorData { createdAt DateTime @default(now()) @db.Timestamptz(6) monitor Monitor @relation(fields: [monitorId], references: [id], onUpdate: Cascade, onDelete: Cascade) + + @@index([createdAt]) } // Use for record latest monitor status, for example tls status diff --git a/src/server/model/monitor/index.ts b/src/server/model/monitor/index.ts index c115ca2..cf6f1a9 100644 --- a/src/server/model/monitor/index.ts +++ b/src/server/model/monitor/index.ts @@ -37,6 +37,9 @@ export function getMonitorData( value: true, createdAt: true, }, + orderBy: { + createdAt: 'asc', + }, }); }