Class: ChatName

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

Constant Summary collapse

LAST_USED_AT_INTERVAL =
1.hour
MAX_PARAM_LENGTH =
8192

Constants inherited from ApplicationRecord

ApplicationRecord::MAX_PLUCK

Constants included from HasCheckConstraints

HasCheckConstraints::NOT_NULL_CHECK_PATTERN

Constants included from ResetOnColumnErrors

ResetOnColumnErrors::MAX_RESET_PERIOD

Instance Method Summary collapse

Methods inherited from ApplicationRecord

===, cached_column_list, #create_or_load_association, current_transaction, declarative_enum, default_select_columns, delete_all_returning, #deleted_from_database?, id_in, id_not_in, iid_in, nullable_column?, 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 Organizations::Sharding

#sharding_organization

Methods included from ResetOnColumnErrors

#reset_on_union_error, #reset_on_unknown_attribute_error

Methods included from Gitlab::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.



32
33
34
35
36
37
38
39
40
# File 'app/models/chat_name.rb', line 32

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)


42
43
44
# File 'app/models/chat_name.rb', line 42

def update_last_used_at?
  last_used_at.nil? || last_used_at.before?(LAST_USED_AT_INTERVAL.ago)
end