Class: ChatName
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- ChatName
- Defined in:
- app/models/chat_name.rb
Constant Summary collapse
- LAST_USED_AT_INTERVAL =
1.hour
Constants inherited from ApplicationRecord
Constants included from ResetOnUnionError
ResetOnUnionError::MAX_RESET_PERIOD
Instance Method Summary collapse
-
#update_last_used_at ⇒ Object
Updates the “last_used_timestamp” but only if it wasn’t already updated recently.
- #update_last_used_at? ⇒ Boolean
Methods inherited from ApplicationRecord
cached_column_list, #create_or_load_association, declarative_enum, default_select_columns, id_in, id_not_in, iid_in, pluck_primary_key, primary_key_in, #readable_by?, safe_ensure_unique, safe_find_or_create_by, safe_find_or_create_by!, #to_ability_name, underscore, where_exists, where_not_exists, with_fast_read_statement_timeout, without_order
Methods included from SensitiveSerializableHash
Instance Method Details
#update_last_used_at ⇒ Object
Updates the “last_used_timestamp” but only if it wasn’t already updated recently.
The throttling this method uses is put in place to ensure that high chat traffic doesn’t result in many UPDATE queries being performed.
19 20 21 22 23 24 25 26 27 |
# File 'app/models/chat_name.rb', line 19 def update_last_used_at return unless update_last_used_at? obtained = Gitlab::ExclusiveLease .new("chat_name/last_used_at/#{id}", timeout: LAST_USED_AT_INTERVAL.to_i) .try_obtain touch(:last_used_at) if obtained end |
#update_last_used_at? ⇒ Boolean
29 30 31 |
# File 'app/models/chat_name.rb', line 29 def update_last_used_at? last_used_at.nil? || last_used_at > LAST_USED_AT_INTERVAL.ago end |