From c29f84f71826d8452c06685ce35fd1dfd7caae4f Mon Sep 17 00:00:00 2001 From: bcmmbaga Date: Mon, 6 Jan 2025 13:02:52 +0300 Subject: [PATCH] Refactor user lastlogin update Signed-off-by: bcmmbaga --- management/server/store/sql_store.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/management/server/store/sql_store.go b/management/server/store/sql_store.go index 9caa5d209d4..7b1a634113d 100644 --- a/management/server/store/sql_store.go +++ b/management/server/store/sql_store.go @@ -886,10 +886,6 @@ func (s *SqlStore) GetAccountSettings(ctx context.Context, lockStrength LockingS // SaveUserLastLogin stores the last login time for a user in DB. func (s *SqlStore) SaveUserLastLogin(ctx context.Context, accountID, userID string, lastLogin time.Time) error { - if lastLogin.IsZero() { - return nil - } - var user types.User result := s.db.First(&user, accountAndIDQueryCondition, accountID, userID) if result.Error != nil { @@ -898,9 +894,13 @@ func (s *SqlStore) SaveUserLastLogin(ctx context.Context, accountID, userID stri } return status.NewGetUserFromStoreError() } - user.LastLogin = &lastLogin - return s.db.Save(&user).Error + if !lastLogin.IsZero() { + user.LastLogin = &lastLogin + return s.db.Save(&user).Error + } + + return nil } func (s *SqlStore) GetPostureCheckByChecksDefinition(accountID string, checks *posture.ChecksDefinition) (*posture.Checks, error) {