mirror of
https://github.com/linux-do/new-api.git
synced 2025-09-25 11:26:38 +08:00
feat: update cache #204
This commit is contained in:
parent
c6e85d5b57
commit
65b85377c6
@ -168,7 +168,11 @@ func CacheUpdateUserQuota(id int) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
err = common.RedisSet(fmt.Sprintf("user_quota:%d", id), fmt.Sprintf("%d", quota), time.Duration(UserId2QuotaCacheSeconds)*time.Second)
|
return CacheSetUserQuota(id, quota)
|
||||||
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,6 +102,9 @@ func GetTokenById(id int) (*Token, error) {
|
|||||||
token := Token{Id: id}
|
token := Token{Id: id}
|
||||||
var err error = nil
|
var err error = nil
|
||||||
err = DB.First(&token, "id = ?", id).Error
|
err = DB.First(&token, "id = ?", id).Error
|
||||||
|
if err != nil {
|
||||||
|
go cacheSetToken(&token)
|
||||||
|
}
|
||||||
return &token, err
|
return &token, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -410,6 +410,11 @@ func ValidateAccessToken(token string) (user *User) {
|
|||||||
|
|
||||||
func GetUserQuota(id int) (quota int, err error) {
|
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 common.RedisEnabled {
|
||||||
|
go CacheSetUserQuota(id, quota)
|
||||||
|
}
|
||||||
|
}
|
||||||
return quota, err
|
return quota, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user