🗑 优化无效数据清理
This commit is contained in:
		
							parent
							
								
									438a8c393c
								
							
						
					
					
						commit
						bb966b2c82
					
				@ -1,7 +1,7 @@
 | 
				
			|||||||
<div align="center">
 | 
					<div align="center">
 | 
				
			||||||
  <img width="500" style="max-width:100%" src="resource/static/brand.png" title="哪吒监控">
 | 
					  <img width="500" style="max-width:100%" src="resource/static/brand.png" title="哪吒监控">
 | 
				
			||||||
  <br><br>
 | 
					  <br><br>
 | 
				
			||||||
<img src="https://img.shields.io/github/workflow/status/naiba/nezha/Dashboard%20image?label=Dash%20v0.9.9&logo=github&style=for-the-badge"> <img src="https://img.shields.io/github/v/release/naiba/nezha?color=brightgreen&label=Agent&style=for-the-badge&logo=github"> <img src="https://img.shields.io/github/workflow/status/naiba/nezha/Agent%20release?label=Agent%20CI&logo=github&style=for-the-badge"> <img src="https://img.shields.io/badge/Installer-v0.6.4-brightgreen?style=for-the-badge&logo=linux">
 | 
					<img src="https://img.shields.io/github/workflow/status/naiba/nezha/Dashboard%20image?label=Dash%20v0.9.10&logo=github&style=for-the-badge"> <img src="https://img.shields.io/github/v/release/naiba/nezha?color=brightgreen&label=Agent&style=for-the-badge&logo=github"> <img src="https://img.shields.io/github/workflow/status/naiba/nezha/Agent%20release?label=Agent%20CI&logo=github&style=for-the-badge"> <img src="https://img.shields.io/badge/Installer-v0.6.4-brightgreen?style=for-the-badge&logo=linux">
 | 
				
			||||||
  <br>
 | 
					  <br>
 | 
				
			||||||
  <br>
 | 
					  <br>
 | 
				
			||||||
  <p>:trollface: <b>哪吒监控</b> 一站式轻监控轻运维系统。支持系统状态、HTTP(SSL 证书变更、即将到期、到期)、TCP、Ping 监控报警,命令批量执行和计划任务。</p>	
 | 
					  <p>:trollface: <b>哪吒监控</b> 一站式轻监控轻运维系统。支持系统状态、HTTP(SSL 证书变更、即将到期、到期)、TCP、Ping 监控报警,命令批量执行和计划任务。</p>	
 | 
				
			||||||
 | 
				
			|||||||
@ -93,7 +93,10 @@ func recordTransferHourlyUsage() {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func cleanMonitorHistory() {
 | 
					func cleanMonitorHistory() {
 | 
				
			||||||
	dao.DB.Unscoped().Delete(&model.MonitorHistory{}, "created_at < ?", time.Now().AddDate(0, 0, -30))
 | 
						// 清理无效数据
 | 
				
			||||||
 | 
						dao.DB.Unscoped().Delete(&model.MonitorHistory{}, "created_at < ? OR monitor_id NOT IN (SELECT `id` FROM monitors)", time.Now().AddDate(0, 0, -30))
 | 
				
			||||||
 | 
						dao.DB.Unscoped().Delete(&model.Transfer{}, "server_id NOT IN (SELECT `id` FROM servers)")
 | 
				
			||||||
 | 
						// 计算可清理流量记录的时长
 | 
				
			||||||
	var allServerKeep time.Time
 | 
						var allServerKeep time.Time
 | 
				
			||||||
	specialServerKeep := make(map[uint64]time.Time)
 | 
						specialServerKeep := make(map[uint64]time.Time)
 | 
				
			||||||
	var specialServerIDs []uint64
 | 
						var specialServerIDs []uint64
 | 
				
			||||||
 | 
				
			|||||||
@ -22,8 +22,6 @@ type User struct {
 | 
				
			|||||||
	Token        string    `gorm:"UNIQUE_INDEX" json:"-"`   // 认证 Token
 | 
						Token        string    `gorm:"UNIQUE_INDEX" json:"-"`   // 认证 Token
 | 
				
			||||||
	TokenExpired time.Time `json:"token_expired,omitempty"` // Token 过期时间
 | 
						TokenExpired time.Time `json:"token_expired,omitempty"` // Token 过期时间
 | 
				
			||||||
	SuperAdmin   bool      `json:"super_admin,omitempty"`   // 超级管理员
 | 
						SuperAdmin   bool      `json:"super_admin,omitempty"`   // 超级管理员
 | 
				
			||||||
 | 
					 | 
				
			||||||
	TeamsID []uint64 `gorm:"-"`
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func NewUserFromGitHub(gu *github.User) User {
 | 
					func NewUserFromGitHub(gu *github.User) User {
 | 
				
			||||||
 | 
				
			|||||||
@ -13,7 +13,7 @@ import (
 | 
				
			|||||||
	pb "github.com/naiba/nezha/proto"
 | 
						pb "github.com/naiba/nezha/proto"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
var Version = "v0.9.9" // !!记得修改 README 中的 badge 版本!!
 | 
					var Version = "v0.9.10" // !!记得修改 README 中的 badge 版本!!
 | 
				
			||||||
 | 
					
 | 
				
			||||||
var (
 | 
					var (
 | 
				
			||||||
	Conf  *model.Config
 | 
						Conf  *model.Config
 | 
				
			||||||
 | 
				
			|||||||
@ -164,9 +164,6 @@ func (ss *ServiceSentinel) OnMonitorUpdate() {
 | 
				
			|||||||
	var mhs []model.MonitorHistory
 | 
						var mhs []model.MonitorHistory
 | 
				
			||||||
	DB.Where("created_at >= ? AND created_at < ?", today.AddDate(0, 0, -29), today).Find(&mhs)
 | 
						DB.Where("created_at >= ? AND created_at < ?", today.AddDate(0, 0, -29), today).Find(&mhs)
 | 
				
			||||||
	for i := 0; i < len(mhs); i++ {
 | 
						for i := 0; i < len(mhs); i++ {
 | 
				
			||||||
		if ServiceSentinelShared.monthlyStatus[mhs[i].MonitorID] == nil {
 | 
					 | 
				
			||||||
			continue
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		dayIndex := 28 - (int(today.Sub(mhs[i].CreatedAt).Hours()) / 24)
 | 
							dayIndex := 28 - (int(today.Sub(mhs[i].CreatedAt).Hours()) / 24)
 | 
				
			||||||
		if mhs[i].Successful {
 | 
							if mhs[i].Successful {
 | 
				
			||||||
			ServiceSentinelShared.monthlyStatus[mhs[i].MonitorID].TotalUp++
 | 
								ServiceSentinelShared.monthlyStatus[mhs[i].MonitorID].TotalUp++
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user