Commit 1b36def8 authored by Dylan Griffith's avatar Dylan Griffith

Merge branch 'project-topics-remove-tags' into 'master'

Replace 'tags' with 'topics' association on project

See merge request gitlab-org/gitlab!62549
parents e1cd303d 784c5dab
...@@ -36,7 +36,7 @@ class Dashboard::ProjectsController < Dashboard::ApplicationController ...@@ -36,7 +36,7 @@ class Dashboard::ProjectsController < Dashboard::ApplicationController
# rubocop: disable CodeReuse/ActiveRecord # rubocop: disable CodeReuse/ActiveRecord
def starred def starred
@projects = load_projects(params.merge(starred: true)) @projects = load_projects(params.merge(starred: true))
.includes(:forked_from_project, :tags) .includes(:forked_from_project, :topics)
@groups = [] @groups = []
......
...@@ -127,14 +127,10 @@ class Project < ApplicationRecord ...@@ -127,14 +127,10 @@ class Project < ApplicationRecord
after_create :check_repository_absence! after_create :check_repository_absence!
acts_as_ordered_taggable_on :topics acts_as_ordered_taggable_on :topics
# The 'tag_list' alias and the 'tags' association are required during the 'tags -> topics' migration # The 'tag_list' alias is required during the 'tags -> topics' migration
# TODO: eliminate 'tag_list' and 'tags' in the further process of the migration # TODO: eliminate 'tag_list' in the further process of the migration
# https://gitlab.com/gitlab-org/gitlab/-/issues/328226 # https://gitlab.com/gitlab-org/gitlab/-/issues/328226
alias_attribute :tag_list, :topic_list 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 :old_path_with_namespace
attr_accessor :template_name attr_accessor :template_name
...@@ -637,7 +633,7 @@ class Project < ApplicationRecord ...@@ -637,7 +633,7 @@ class Project < ApplicationRecord
mount_uploader :bfg_object_map, AttachmentUploader mount_uploader :bfg_object_map, AttachmentUploader
def self.with_api_entity_associations 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 end
def self.with_web_entity_associations def self.with_web_entity_associations
......
...@@ -38,12 +38,12 @@ module API ...@@ -38,12 +38,12 @@ module API
# rubocop: disable CodeReuse/ActiveRecord # rubocop: disable CodeReuse/ActiveRecord
def self.preload_relation(projects_relation, options = {}) def self.preload_relation(projects_relation, options = {})
# Preloading topics, should be done with using only `:tags`, # Preloading topics, should be done with using only `:topics`,
# as `:tags` are defined as: `has_many :tags, through: :taggings` # as `:topics` are defined as: `has_many :topics, through: :taggings`
# N+1 is solved then by using `subject.tags.map(&:name)` # 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 # MR describing the solution: https://gitlab.com/gitlab-org/gitlab-foss/merge_requests/20555
projects_relation.preload(:project_feature, :route) projects_relation.preload(:project_feature, :route)
.preload(:import_state, :tags) .preload(:import_state, :topics)
.preload(:auto_devops) .preload(:auto_devops)
.preload(namespace: [:route, :owner]) .preload(namespace: [:route, :owner])
end end
...@@ -58,7 +58,7 @@ module API ...@@ -58,7 +58,7 @@ module API
# through the database, it will trigger a new query, ending up # through the database, it will trigger a new query, ending up
# in an N+1 if we have several projects # in an N+1 if we have several projects
strong_memoize(:topic_names) do 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 end
end end
......
...@@ -123,9 +123,9 @@ module API ...@@ -123,9 +123,9 @@ module API
# rubocop: disable CodeReuse/ActiveRecord # rubocop: disable CodeReuse/ActiveRecord
def self.preload_relation(projects_relation, options = {}) def self.preload_relation(projects_relation, options = {})
# Preloading tags, should be done with using only `:tags`, # Preloading topics, should be done with using only `:topics`,
# as `:tags` are defined as: `has_many :tags, through: :taggings` # as `:topics` are defined as: `has_many :topics, through: :taggings`
# N+1 is solved then by using `subject.tags.map(&:name)` # 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 # MR describing the solution: https://gitlab.com/gitlab-org/gitlab-foss/merge_requests/20555
super(projects_relation).preload(group: :namespace_settings) super(projects_relation).preload(group: :namespace_settings)
.preload(:ci_cd_settings) .preload(:ci_cd_settings)
...@@ -136,7 +136,7 @@ module API ...@@ -136,7 +136,7 @@ module API
.preload(project_group_links: { group: :route }, .preload(project_group_links: { group: :route },
fork_network: :root_project, fork_network: :root_project,
fork_network_member: :forked_from_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 end
# rubocop: enable CodeReuse/ActiveRecord # rubocop: enable CodeReuse/ActiveRecord
......
...@@ -345,7 +345,6 @@ project: ...@@ -345,7 +345,6 @@ project:
- external_approval_rules - external_approval_rules
- taggings - taggings
- base_tags - base_tags
- tags
- topic_taggings - topic_taggings
- topics - topics
- chat_services - chat_services
......
...@@ -6930,11 +6930,6 @@ RSpec.describe Project, factory_default: :keep do ...@@ -6930,11 +6930,6 @@ RSpec.describe Project, factory_default: :keep do
it 'tag_list returns correct string array' do it 'tag_list returns correct string array' do
expect(project.tag_list).to match_array(%w[topic1 topic2 topic3]) expect(project.tag_list).to match_array(%w[topic1 topic2 topic3])
end 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
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment