avoid db check in updates

This commit is contained in:
Alireza Ahmadi
2024-05-29 23:27:21 +02:00
parent aca870e78f
commit 9547038164
+13 -1
View File
@@ -7,10 +7,12 @@ import (
"s-ui/database"
"s-ui/database/model"
"s-ui/singbox"
"strconv"
"time"
)
var ApiAddr string
var LastUpdate int64
type ConfigService struct {
ClientService
@@ -177,17 +179,27 @@ func (s *ConfigService) SaveChanges(changes map[string]string, loginUser string)
return err
}
LastUpdate = dt
return nil
}
func (s *ConfigService) CheckChnages(lu string) (bool, error) {
func (s *ConfigService) CheckChanges(lu string) (bool, error) {
if lu == "" {
return true, nil
}
if LastUpdate == 0 {
db := database.GetDB()
var count int64
err := db.Model(model.Changes{}).Where("date_time > " + lu).Count(&count).Error
if err == nil {
LastUpdate = time.Now().Unix()
}
return count > 0, err
} else {
intLu, err := strconv.ParseInt(lu, 10, 64)
return LastUpdate > intLu, err
}
}
func (s *ConfigService) Save(data *[]byte) error {