PERF: Throttle updates to API key last_used_at (#16390)
Co-authored-by: David Taylor <david@taylorhq.com>
This commit is contained in:
parent
68c74e9b93
commit
1203121ac1
|
@ -67,6 +67,13 @@ class ApiKey < ActiveRecord::Base
|
|||
|
||||
api_key_scopes.blank? || api_key_scopes.any? { |s| s.permits?(env) }
|
||||
end
|
||||
|
||||
def update_last_used!(now = Time.zone.now)
|
||||
return if last_used_at && (last_used_at > 1.minute.ago)
|
||||
|
||||
# using update_column to avoid the AR transaction
|
||||
update_column(:last_used_at, now)
|
||||
end
|
||||
end
|
||||
|
||||
# == Schema Information
|
||||
|
|
|
@ -385,7 +385,9 @@ class Auth::DefaultCurrentUserProvider
|
|||
end
|
||||
|
||||
if user && can_write?
|
||||
api_key.update_columns(last_used_at: Time.zone.now)
|
||||
Scheduler::Defer.later "Updating api_key last_used" do
|
||||
api_key.update_last_used!
|
||||
end
|
||||
end
|
||||
|
||||
user
|
||||
|
|
Loading…
Reference in New Issue