mirror of
https://github.com/linux-do/new-api.git
synced 2025-09-18 08:26:37 +08:00
feat: update cache
This commit is contained in:
parent
4ef98ba7eb
commit
e6765ef32d
@ -25,9 +25,6 @@ var token2UserId = make(map[string]int)
|
|||||||
var token2UserIdLock sync.RWMutex
|
var token2UserIdLock sync.RWMutex
|
||||||
|
|
||||||
func cacheSetToken(token *Token) error {
|
func cacheSetToken(token *Token) error {
|
||||||
if !common.RedisEnabled {
|
|
||||||
return token.SelectUpdate()
|
|
||||||
}
|
|
||||||
jsonBytes, err := json.Marshal(token)
|
jsonBytes, err := json.Marshal(token)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -168,10 +165,10 @@ func CacheUpdateUserQuota(id int) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return CacheSetUserQuota(id, quota)
|
return cacheSetUserQuota(id, quota)
|
||||||
}
|
}
|
||||||
|
|
||||||
func CacheSetUserQuota(id int, quota int) error {
|
func cacheSetUserQuota(id int, quota int) error {
|
||||||
err := common.RedisSet(fmt.Sprintf("user_quota:%d", id), fmt.Sprintf("%d", quota), time.Duration(UserId2QuotaCacheSeconds)*time.Second)
|
err := common.RedisSet(fmt.Sprintf("user_quota:%d", id), fmt.Sprintf("%d", quota), time.Duration(UserId2QuotaCacheSeconds)*time.Second)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -412,7 +412,7 @@ func GetUserQuota(id int) (quota int, err error) {
|
|||||||
err = DB.Model(&User{}).Where("id = ?", id).Select("quota").Find("a).Error
|
err = DB.Model(&User{}).Where("id = ?", id).Select("quota").Find("a).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if common.RedisEnabled {
|
if common.RedisEnabled {
|
||||||
go CacheSetUserQuota(id, quota)
|
go cacheSetUserQuota(id, quota)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return quota, err
|
return quota, err
|
||||||
|
Loading…
Reference in New Issue
Block a user