diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-05-11 15:12:30 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-05-11 15:12:30 +0300 |
commit | 0b54f87a31c23544ca5917bf772ce9c64a61562c (patch) | |
tree | 79d56df6750e84fd4a10205d9dcce293f7c5d491 /app/services/keys | |
parent | e348fb4c1b9eaf21655001dc4346ceb0c0c3d5b4 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/services/keys')
-rw-r--r-- | app/services/keys/last_used_service.rb | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/app/services/keys/last_used_service.rb b/app/services/keys/last_used_service.rb index daef544bac0..3683c03b7a4 100644 --- a/app/services/keys/last_used_service.rb +++ b/app/services/keys/last_used_service.rb @@ -2,7 +2,7 @@ module Keys class LastUsedService - TIMEOUT = 1.day.to_i + TIMEOUT = 1.day attr_reader :key @@ -12,26 +12,24 @@ module Keys end def execute + return unless update? + # We _only_ want to update last_used_at and not also updated_at (which # would be updated when using #touch). - key.update_column(:last_used_at, Time.zone.now) if update? + key.update_column(:last_used_at, Time.zone.now) end - def update? - return false if ::Gitlab::Database.read_only? - - last_used = key.last_used_at + def execute_async + return unless update? - return false if last_used && (Time.zone.now - last_used) <= TIMEOUT - - !!redis_lease.try_obtain + ::SshKeys::UpdateLastUsedAtWorker.perform_async(key.id) end - private + def update? + return false if ::Gitlab::Database.read_only? - def redis_lease - Gitlab::ExclusiveLease - .new("key_update_last_used_at:#{key.id}", timeout: TIMEOUT) + last_used = key.last_used_at + last_used.blank? || last_used <= TIMEOUT.ago end end end |