From 43e02cb987f100c6ff67694e7d1099a139d8dee2 Mon Sep 17 00:00:00 2001
From: zhangzengfei <zhangzengfei@smartai.com>
Date: 星期日, 25 八月 2024 23:31:08 +0800
Subject: [PATCH] 修复ntpdate命令
---
models/cache.go | 29 ++++++++++++++++++++++++++---
1 files changed, 26 insertions(+), 3 deletions(-)
diff --git a/models/cache.go b/models/cache.go
index f3580d2..5c0dd44 100644
--- a/models/cache.go
+++ b/models/cache.go
@@ -2,6 +2,7 @@
type Cache struct {
Id uint `gorm:"column:id;primary_key;auto_increment;unique;not null;"`
+ Type string `gorm:"column:type;"` // 娑堟伅绫诲瀷 1400, basic
Data string `gorm:"column:data;type:text"`
CreateTime int64 `gorm:"column:create_time;"`
Retry int `gorm:"column:retry;"`
@@ -9,6 +10,10 @@
func (c *Cache) TableName() string {
return "caches"
+}
+
+func (c *Cache) First() error {
+ return db.Table(c.TableName()).First(c).Error
}
func (c *Cache) FindAll() ([]Cache, error) {
@@ -20,10 +25,28 @@
return caches, nil
}
-func (c *Cache) Update() error {
- return db.Table(c.TableName()).Save(&c).Error
+func (c *Cache) Count() (int64, error) {
+ var total int64
+ if err := db.Table(c.TableName()).Count(&total).Error; err != nil {
+ return total, err
+ }
+
+ return total, nil
+}
+
+func (c *Cache) Save() error {
+ return db.Table(c.TableName()).Save(c).Error
+}
+
+func (c *Cache) UpdateRetryCount() error {
+ return db.Table(c.TableName()).Where("id = ?", c.Id).Update("retry", c.Retry+1).Error
}
func (c *Cache) Delete() error {
- return db.Table(c.TableName()).Delete("id = ?", c.Id).Error
+ return db.Table(c.TableName()).Where("id = ?", c.Id).Delete(c).Error
+}
+
+func (c *Cache) Clean() error {
+ sql := "DELETE FROM caches WHERE id NOT IN (SELECT id FROM caches ORDER BY id DESC LIMIT 15000);"
+ return db.Table(c.TableName()).Exec(sql).Error
}
--
Gitblit v1.8.0