refactor: update users api
This commit is contained in:
parent
5c1d4077e2
commit
0a2e23c285
|
@ -46,6 +46,7 @@ func (rt *Router) userGets(c *gin.Context) {
|
|||
order := ginx.QueryStr(c, "order", "username")
|
||||
desc := ginx.QueryBool(c, "desc", false)
|
||||
|
||||
rt.UserCache.UpdateUsersLastActiveTime()
|
||||
total, err := models.UserTotal(rt.Ctx, query, stime, etime)
|
||||
ginx.Dangerous(err)
|
||||
|
||||
|
|
|
@ -215,13 +215,13 @@ func (uc *UserCacheType) loopUpdateLastActiveTime() {
|
|||
duration := 5 * time.Minute
|
||||
for {
|
||||
time.Sleep(duration)
|
||||
if err := uc.updateUsersLastActiveTime(); err != nil {
|
||||
if err := uc.UpdateUsersLastActiveTime(); err != nil {
|
||||
logger.Warningf("failed to update users' last active time: %v", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (uc *UserCacheType) updateUsersLastActiveTime() error {
|
||||
func (uc *UserCacheType) UpdateUsersLastActiveTime() error {
|
||||
// read the full list of users from the database
|
||||
users, err := models.UserGetAll(uc.ctx)
|
||||
if err != nil {
|
||||
|
|
|
@ -205,8 +205,10 @@ func (u *User) Add(ctx *ctx.Context) error {
|
|||
}
|
||||
|
||||
func (u *User) Update(ctx *ctx.Context, selectField interface{}, selectFields ...interface{}) error {
|
||||
if err := u.Verify(); err != nil {
|
||||
return err
|
||||
if u.Belong == "" {
|
||||
if err := u.Verify(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return DB(ctx).Model(u).Select(selectField, selectFields...).Updates(u).Error
|
||||
|
|
Loading…
Reference in New Issue