From 784c5dabe6cbb2393a306b1331d4e648631f005b Mon Sep 17 00:00:00 2001 From: Jonas Waelter Date: Wed, 26 May 2021 08:54:18 +0200 Subject: [PATCH] Replace 'tags' with 'topics' association on project Changelog: removed --- app/controllers/dashboard/projects_controller.rb | 2 +- app/models/project.rb | 10 +++------- lib/api/entities/basic_project_details.rb | 10 +++++----- lib/api/entities/project.rb | 8 ++++---- spec/lib/gitlab/import_export/all_models.yml | 1 - spec/models/project_spec.rb | 5 ----- 6 files changed, 13 insertions(+), 23 deletions(-) diff --git a/app/controllers/dashboard/projects_controller.rb b/app/controllers/dashboard/projects_controller.rb index 7cb396253715d4..01bb930a51b479 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 59d8bbeab77688..2bf0c4a5e275aa 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 91831fe2bdfdaa..c75b74b4368a29 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 9f13586b24af43..fabad33f52af9a 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 dc7fedd6b4f273..52171703636714 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 886c381c475317..f97c867b14fbb4 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 -- GitLab