mirror of
https://github.com/grafana/grafana.git
synced 2026-08-27 05:47:26 -05:00
Users: Add config option to control how often last_seen is updated (#88721)
Users: Add config option to control how often last_seen is updated Co-authored-by: Karl Persson <kalle.persson92@gmail.com>
This commit is contained in:
@@ -301,15 +301,15 @@ func (s *Service) UpdateLastSeenAt(ctx context.Context, cmd *user.UpdateUserLast
|
||||
return err
|
||||
}
|
||||
|
||||
if !shouldUpdateLastSeen(u.LastSeenAt) {
|
||||
if !s.shouldUpdateLastSeen(u.LastSeenAt) {
|
||||
return user.ErrLastSeenUpToDate
|
||||
}
|
||||
|
||||
return s.store.UpdateLastSeenAt(ctx, cmd)
|
||||
}
|
||||
|
||||
func shouldUpdateLastSeen(t time.Time) bool {
|
||||
return time.Since(t) > time.Minute*15
|
||||
func (s *Service) shouldUpdateLastSeen(t time.Time) bool {
|
||||
return time.Since(t) > s.cfg.UserLastSeenUpdateInterval
|
||||
}
|
||||
|
||||
func (s *Service) GetSignedInUser(ctx context.Context, query *user.GetSignedInUserQuery) (*user.SignedInUser, error) {
|
||||
|
||||
@@ -221,6 +221,7 @@ func TestUpdateLastSeenAt(t *testing.T) {
|
||||
tracer: tracing.InitializeTracerForTest(),
|
||||
}
|
||||
userService.cfg = setting.NewCfg()
|
||||
userService.cfg.UserLastSeenUpdateInterval = 5 * time.Minute
|
||||
|
||||
t.Run("update last seen at", func(t *testing.T) {
|
||||
userStore.ExpectedSignedInUser = &user.SignedInUser{UserID: 1, OrgID: 1, Email: "email", Login: "login", Name: "name", LastSeenAt: time.Now().Add(-20 * time.Minute)}
|
||||
|
||||
Reference in New Issue
Block a user