优化请求hook处理

This commit is contained in:
孟帅
2023-02-09 14:35:35 +08:00
parent 1efbf698e2
commit f7307e4fd4
4 changed files with 47 additions and 30 deletions

View File

@@ -8,6 +8,7 @@ import (
"github.com/gogf/gf/v2/os/gtime"
"github.com/gogf/gf/v2/os/gtimer"
"hotgo/internal/library/contexts"
"hotgo/utility/simple"
"sync"
"time"
)
@@ -69,12 +70,15 @@ func (s *sHook) LastActive(r *ghttp.Request) {
}
if allow(memberId) {
_, err := g.Model("admin_member").Ctx(ctx).
Where("id", memberId).
Data(g.Map{"last_active_at": gtime.Now()}).
Update()
if err != nil {
g.Log().Warningf(ctx, "hook LastActive err:%+v, memberId:%v", err, memberId)
}
simple.SafeGo(ctx, func(ctx context.Context) {
_, err := g.Model("admin_member").Ctx(ctx).
Where("id", memberId).
WhereLT("last_active_at", gtime.Now()).
Data(g.Map{"last_active_at": gtime.Now()}).
Update()
if err != nil {
g.Log().Warningf(ctx, "hook LastActive err:%+v, memberId:%v", err, memberId)
}
})
}
}