Class: Projects::Topic
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Projects::Topic
- Includes:
- Avatarable, Gitlab::SQL::Pattern
- Defined in:
- app/models/projects/topic.rb
Constant Summary collapse
- SLUG_ALLOWED_REGEX =
%r{\A[a-zA-Z0-9_\-.]+\z}
Constants included from Gitlab::SQL::Pattern
Gitlab::SQL::Pattern::MIN_CHARS_FOR_PARTIAL_MATCHING, Gitlab::SQL::Pattern::REGEX_QUOTED_TERM
Constants included from Avatarable
Avatarable::ALLOWED_IMAGE_SCALER_WIDTHS, Avatarable::COMBINED_AVATAR_SIZES, Avatarable::COMBINED_AVATAR_SIZES_RETINA, Avatarable::GROUP_AVATAR_SIZES, Avatarable::MAXIMUM_FILE_SIZE, Avatarable::PROJECT_AVATAR_SIZES, Avatarable::USER_AVATAR_SIZES
Constants inherited from ApplicationRecord
Constants included from HasCheckConstraints
HasCheckConstraints::NOT_NULL_CHECK_PATTERN
Constants included from ResetOnColumnErrors
ResetOnColumnErrors::MAX_RESET_PERIOD
Class Method Summary collapse
- .find_by_name_case_insensitive(name) ⇒ Object
- .search(query) ⇒ Object
- .update_non_private_projects_counter(ids_before, ids_after, project_visibility_level_before, project_visibility_level_after) ⇒ Object
Instance Method Summary collapse
Methods included from Gitlab::SQL::Pattern
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, nullable_column?, 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 ResetOnColumnErrors
#reset_on_union_error, #reset_on_unknown_attribute_error
Methods included from Gitlab::SensitiveSerializableHash
Class Method Details
.find_by_name_case_insensitive(name) ⇒ Object
47 48 49 |
# File 'app/models/projects/topic.rb', line 47 def find_by_name_case_insensitive(name) find_by('LOWER(name) = ?', name.downcase) end |
.search(query) ⇒ Object
51 52 53 |
# File 'app/models/projects/topic.rb', line 51 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
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'app/models/projects/topic.rb', line 55 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_name ⇒ Object
42 43 44 |
# File 'app/models/projects/topic.rb', line 42 def title_or_name title || name end |
#uploads_sharding_key ⇒ Object
79 80 81 |
# File 'app/models/projects/topic.rb', line 79 def uploads_sharding_key { organization_id: organization_id } end |