diff --git a/app/controllers/dashboard/projects_controller.rb b/app/controllers/dashboard/projects_controller.rb index 7cb396253715d4170afaf78f60f77dcbe6185ef7..01bb930a51b479234633834300bcc3f965acbc29 100644 --- a/app/controllers/dashboard/projects_controller.rb +++ b/app/controllers/dashboard/projects_controller.rb @@ -36,7 +36,7 @@ def index # rubocop: disable CodeReuse/ActiveRecord def starred @projects = load_projects(params.merge(starred: true)) - .includes(:forked_from_project, :tags) + .includes(:forked_from_project, :topics) @groups = [] diff --git a/app/models/project.rb b/app/models/project.rb index 59d8bbeab776887f9574e506be5d75b9fa49fd32..2bf0c4a5e275aaed21184bb2dde018a09572e8db 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -127,14 +127,10 @@ class Project < ApplicationRecord after_create :check_repository_absence! acts_as_ordered_taggable_on :topics - # The 'tag_list' alias and the 'tags' association are required during the 'tags -> topics' migration - # TODO: eliminate 'tag_list' and 'tags' in the further process of the migration + # The 'tag_list' alias is required during the 'tags -> topics' migration + # TODO: eliminate 'tag_list' in the further process of the migration # https://gitlab.com/gitlab-org/gitlab/-/issues/328226 alias_attribute :tag_list, :topic_list - has_many :tags, -> { order("#{ActsAsTaggableOn::Tagging.table_name}.id") }, - class_name: 'ActsAsTaggableOn::Tag', - through: :topic_taggings, - source: :tag attr_accessor :old_path_with_namespace attr_accessor :template_name @@ -637,7 +633,7 @@ class Project < ApplicationRecord mount_uploader :bfg_object_map, AttachmentUploader def self.with_api_entity_associations - preload(:project_feature, :route, :tags, :group, :timelogs, namespace: [:route, :owner]) + preload(:project_feature, :route, :topics, :group, :timelogs, namespace: [:route, :owner]) end def self.with_web_entity_associations diff --git a/lib/api/entities/basic_project_details.rb b/lib/api/entities/basic_project_details.rb index 91831fe2bdfdaa02f74b8c02b9e062a4e3b60d42..c75b74b4368a29f44a0e948f0d333e7cd0dcac90 100644 --- a/lib/api/entities/basic_project_details.rb +++ b/lib/api/entities/basic_project_details.rb @@ -38,12 +38,12 @@ class BasicProjectDetails < Entities::ProjectIdentity # rubocop: disable CodeReuse/ActiveRecord def self.preload_relation(projects_relation, options = {}) - # Preloading topics, should be done with using only `:tags`, - # as `:tags` are defined as: `has_many :tags, through: :taggings` - # N+1 is solved then by using `subject.tags.map(&:name)` + # Preloading topics, should be done with using only `:topics`, + # as `:topics` are defined as: `has_many :topics, through: :taggings` + # N+1 is solved then by using `subject.topics.map(&:name)` # MR describing the solution: https://gitlab.com/gitlab-org/gitlab-foss/merge_requests/20555 projects_relation.preload(:project_feature, :route) - .preload(:import_state, :tags) + .preload(:import_state, :topics) .preload(:auto_devops) .preload(namespace: [:route, :owner]) end @@ -58,7 +58,7 @@ def topic_names # through the database, it will trigger a new query, ending up # in an N+1 if we have several projects strong_memoize(:topic_names) do - project.tags.pluck(:name).sort # rubocop:disable CodeReuse/ActiveRecord + project.topics.pluck(:name).sort # rubocop:disable CodeReuse/ActiveRecord end end end diff --git a/lib/api/entities/project.rb b/lib/api/entities/project.rb index 9f13586b24af43af28e546ec609780347cf517c1..fabad33f52af9aac7c2033ed40120a4720344779 100644 --- a/lib/api/entities/project.rb +++ b/lib/api/entities/project.rb @@ -123,9 +123,9 @@ class Project < BasicProjectDetails # rubocop: disable CodeReuse/ActiveRecord def self.preload_relation(projects_relation, options = {}) - # Preloading tags, should be done with using only `:tags`, - # as `:tags` are defined as: `has_many :tags, through: :taggings` - # N+1 is solved then by using `subject.tags.map(&:name)` + # Preloading topics, should be done with using only `:topics`, + # as `:topics` are defined as: `has_many :topics, through: :taggings` + # N+1 is solved then by using `subject.topics.map(&:name)` # MR describing the solution: https://gitlab.com/gitlab-org/gitlab-foss/merge_requests/20555 super(projects_relation).preload(group: :namespace_settings) .preload(:ci_cd_settings) @@ -136,7 +136,7 @@ def self.preload_relation(projects_relation, options = {}) .preload(project_group_links: { group: :route }, fork_network: :root_project, fork_network_member: :forked_from_project, - forked_from_project: [:route, :tags, :group, :project_feature, namespace: [:route, :owner]]) + forked_from_project: [:route, :topics, :group, :project_feature, namespace: [:route, :owner]]) end # rubocop: enable CodeReuse/ActiveRecord diff --git a/spec/lib/gitlab/import_export/all_models.yml b/spec/lib/gitlab/import_export/all_models.yml index dc7fedd6b4f273c1c7b8175f57c4dcbd15ca071b..5217170363671486bc7d8a1269164c227881f601 100644 --- a/spec/lib/gitlab/import_export/all_models.yml +++ b/spec/lib/gitlab/import_export/all_models.yml @@ -345,7 +345,6 @@ project: - external_approval_rules - taggings - base_tags -- tags - topic_taggings - topics - chat_services diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 886c381c4753171ccd3a796dcfff3b648dc8d39e..f97c867b14fbb449fcc3dc47cd09cd3a321390e8 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -6930,11 +6930,6 @@ def enable_lfs it 'tag_list returns correct string array' do expect(project.tag_list).to match_array(%w[topic1 topic2 topic3]) end - - it 'tags returns correct tag records' do - expect(project.tags.first.class.name).to eq('ActsAsTaggableOn::Tag') - expect(project.tags.map(&:name)).to match_array(%w[topic1 topic2 topic3]) - end end end