Class: UserInteractedProject

Inherits:
ApplicationRecord show all
Extended by:
SuppressCompositePrimaryKeyWarning
Defined in:
app/models/user_interacted_project.rb

Constant Summary collapse

CACHE_EXPIRY_TIME =
1.day

Constants inherited from ApplicationRecord

ApplicationRecord::MAX_PLUCK

Class 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

Class Method Details

.track(event) ⇒ Object


15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/models/user_interacted_project.rb', line 15

def track(event)
  # For events without a project, we simply don't care.
  # An example of this is the creation of a snippet (which
  # is not related to any project).
  return unless event.project_id

  attributes = {
    project_id: event.project_id,
    user_id: event.author_id
  }

  cached_exists?(**attributes) do
    where(attributes).exists? || UserInteractedProject.insert_all([attributes], unique_by: %w(project_id user_id))
    true
  end
end