avoid db check in updates
This commit is contained in:
@@ -7,10 +7,12 @@ import (
|
|||||||
"s-ui/database"
|
"s-ui/database"
|
||||||
"s-ui/database/model"
|
"s-ui/database/model"
|
||||||
"s-ui/singbox"
|
"s-ui/singbox"
|
||||||
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
var ApiAddr string
|
var ApiAddr string
|
||||||
|
var LastUpdate int64
|
||||||
|
|
||||||
type ConfigService struct {
|
type ConfigService struct {
|
||||||
ClientService
|
ClientService
|
||||||
@@ -177,17 +179,27 @@ func (s *ConfigService) SaveChanges(changes map[string]string, loginUser string)
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LastUpdate = dt
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *ConfigService) CheckChnages(lu string) (bool, error) {
|
func (s *ConfigService) CheckChanges(lu string) (bool, error) {
|
||||||
if lu == "" {
|
if lu == "" {
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
if LastUpdate == 0 {
|
||||||
db := database.GetDB()
|
db := database.GetDB()
|
||||||
var count int64
|
var count int64
|
||||||
err := db.Model(model.Changes{}).Where("date_time > " + lu).Count(&count).Error
|
err := db.Model(model.Changes{}).Where("date_time > " + lu).Count(&count).Error
|
||||||
|
if err == nil {
|
||||||
|
LastUpdate = time.Now().Unix()
|
||||||
|
}
|
||||||
return count > 0, err
|
return count > 0, err
|
||||||
|
} else {
|
||||||
|
intLu, err := strconv.ParseInt(lu, 10, 64)
|
||||||
|
return LastUpdate > intLu, err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *ConfigService) Save(data *[]byte) error {
|
func (s *ConfigService) Save(data *[]byte) error {
|
||||||
|
|||||||
Reference in New Issue
Block a user