Class: ChatName

Inherits:
ApplicationRecord show all
Defined in:
app/models/chat_name.rb

Constant Summary collapse

LAST_USED_AT_INTERVAL =
1.hour

Constants inherited from ApplicationRecord

ApplicationRecord::MAX_PLUCK

Constants included from ResetOnUnionError

ResetOnUnionError::MAX_RESET_PERIOD

Instance Method Summary collapse

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

#serializable_hash

Instance Method Details

#update_last_used_atObject

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

Returns:

  • (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