From 7d38634933148133b3e1b29fa41d6e6002e67e74 Mon Sep 17 00:00:00 2001 From: Ko no dio <38449861+lvgj-stack@users.noreply.github.com> Date: Sun, 18 Feb 2024 20:00:36 +0800 Subject: [PATCH] feat: add index on monitor history (#320) --- model/monitor_history.go | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/model/monitor_history.go b/model/monitor_history.go index 56bd498..bbf7535 100644 --- a/model/monitor_history.go +++ b/model/monitor_history.go @@ -1,20 +1,22 @@ package model -const ( - Cycle = iota - Hour - Day - Week - Month +import ( + "time" + + "gorm.io/gorm" ) // MonitorHistory 历史监控记录 type MonitorHistory struct { - Common - MonitorID uint64 - ServerID uint64 - AvgDelay float32 // 平均延迟,毫秒 - Up uint64 // 检查状态良好计数 - Down uint64 // 检查状态异常计数 + ID uint64 `gorm:"primaryKey"` + CreatedAt time.Time `gorm:"index;<-:create;index:idx_server_id_created_at_monitor_id_avg_delay"` + UpdatedAt time.Time `gorm:"autoUpdateTime"` + DeletedAt gorm.DeletedAt `gorm:"index"` + MonitorID uint64 `gorm:"index:idx_server_id_created_at_monitor_id_avg_delay"` + ServerID uint64 `gorm:"index:idx_server_id_created_at_monitor_id_avg_delay"` + AvgDelay float32 `gorm:"index:idx_server_id_created_at_monitor_id_avg_delay"` // 平均延迟,毫秒 + Up uint64 // 检查状态良好计数 + Down uint64 // 检查状态异常计数 Data string } +