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

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.


22
23
24
25
26
27
28
29
30
# File 'app/models/chat_name.rb', line 22

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)

32
33
34
# File 'app/models/chat_name.rb', line 32

def update_last_used_at?
  last_used_at.nil? || last_used_at > LAST_USED_AT_INTERVAL.ago
end