From 023a6573a1b5853ba6e5957e7204430fb0119ba3 Mon Sep 17 00:00:00 2001 From: moonrailgun Date: Tue, 9 Jan 2024 20:39:38 +0800 Subject: [PATCH] fix: fix monitor data sorting problem, add order by and add created at for fetch monitor data --- .../migration.sql | 2 ++ prisma/schema.prisma | 2 ++ src/server/model/monitor/index.ts | 3 +++ 3 files changed, 7 insertions(+) create mode 100644 prisma/migrations/20240109123840_add_monitor_data_created_at_index/migration.sql 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', + }, }); }