mirror of
https://github.com/bufanyun/hotgo.git
synced 2025-08-28 10:09:54 +08:00
优化请求hook处理
This commit is contained in:
@@ -7,11 +7,13 @@
|
||||
package hook
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/net/ghttp"
|
||||
"github.com/gogf/gf/v2/os/gtime"
|
||||
"hotgo/internal/library/contexts"
|
||||
"hotgo/internal/service"
|
||||
"hotgo/utility/simple"
|
||||
)
|
||||
|
||||
// AccessLog 访问日志
|
||||
@@ -29,9 +31,9 @@ func (s *sHook) AccessLog(r *ghttp.Request) {
|
||||
// 计算运行耗时
|
||||
contexts.SetTakeUpTime(ctx, gtime.TimestampMilli()-r.EnterTime)
|
||||
|
||||
go func() {
|
||||
simple.SafeGo(ctx, func(ctx context.Context) {
|
||||
if err := service.SysLog().AutoLog(ctx); err != nil {
|
||||
g.Log().Info(ctx, "hook AccessLog err:", err)
|
||||
g.Log().Warningf(ctx, "hook AccessLog err:%+v", err)
|
||||
}
|
||||
}()
|
||||
})
|
||||
}
|
||||
|
@@ -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)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user