Class: Projects::Topic

Inherits:
ApplicationRecord show all
Includes:
Avatarable, Gitlab::SQL::Pattern
Defined in:
app/models/projects/topic.rb

Constant Summary

Constants included from Gitlab::SQL::Pattern

Gitlab::SQL::Pattern::MIN_CHARS_FOR_PARTIAL_MATCHING, Gitlab::SQL::Pattern::REGEX_QUOTED_WORD

Constants included from Avatarable

Avatarable::ALLOWED_IMAGE_SCALER_WIDTHS, Avatarable::GROUP_AVATAR_SIZES, Avatarable::MAXIMUM_FILE_SIZE, Avatarable::PROJECT_AVATAR_SIZES, Avatarable::USER_AVATAR_SIZES

Constants inherited from ApplicationRecord

ApplicationRecord::MAX_PLUCK

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Avatarable

#avatar_path, #avatar_type, #uncached_avatar_path, #upload_paths

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

.find_by_name_case_insensitive(name) ⇒ Object


31
32
33
# File 'app/models/projects/topic.rb', line 31

def find_by_name_case_insensitive(name)
  find_by('LOWER(name) = ?', name.downcase)
end

.search(query) ⇒ Object


35
36
37
# File 'app/models/projects/topic.rb', line 35

def search(query)
  fuzzy_search(query, [:name, :title])
end

.update_non_private_projects_counter(ids_before, ids_after, project_visibility_level_before, project_visibility_level_after) ⇒ Object


39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'app/models/projects/topic.rb', line 39

def update_non_private_projects_counter(ids_before, ids_after, project_visibility_level_before, project_visibility_level_after)
  project_visibility_level_before ||= project_visibility_level_after

  topics_to_decrement = []
  topics_to_increment = []
  topic_ids_removed = ids_before - ids_after
  topic_ids_retained = ids_before & ids_after
  topic_ids_added = ids_after - ids_before

  if project_visibility_level_before > Gitlab::VisibilityLevel::PRIVATE
    topics_to_decrement += topic_ids_removed
    topics_to_decrement += topic_ids_retained if project_visibility_level_after == Gitlab::VisibilityLevel::PRIVATE
  end

  if project_visibility_level_after > Gitlab::VisibilityLevel::PRIVATE
    topics_to_increment += topic_ids_added
    topics_to_increment += topic_ids_retained if project_visibility_level_before == Gitlab::VisibilityLevel::PRIVATE
  end

  where(id: topics_to_increment).update_counters(non_private_projects_count: 1) unless topics_to_increment.empty?
  where(id: topics_to_decrement).where('non_private_projects_count > 0').update_counters(non_private_projects_count: -1) unless topics_to_decrement.empty?
end

Instance Method Details

#title_or_nameObject


26
27
28
# File 'app/models/projects/topic.rb', line 26

def title_or_name
  title || name
end