summaryrefslogtreecommitdiff
path: root/lib/api/entities.rb
diff options
context:
space:
mode:
authorKamil Trzciński <ayufan@ayufan.eu>2018-07-11 15:27:34 +0200
committerKamil Trzciński <ayufan@ayufan.eu>2018-07-12 13:40:43 +0200
commit1399eb058bfe22dc3fac5ee464e25ea67dd9e59d (patch)
treee708b1902b0bde4b360089e0f868ef41b29d6a79 /lib/api/entities.rb
parent67157de1e4cc482b5321ba2f246bfd80a7893f93 (diff)
downloadgitlab-ce-1399eb058bfe22dc3fac5ee464e25ea67dd9e59d.tar.gz
Fix performance problem of accessing tag list for projects api endpointsfix-performance-problem-of-tags-query
Diffstat (limited to 'lib/api/entities.rb')
-rw-r--r--lib/api/entities.rb15
1 files changed, 11 insertions, 4 deletions
diff --git a/lib/api/entities.rb b/lib/api/entities.rb
index 40df1e79bc7..b52bf34eb90 100644
--- a/lib/api/entities.rb
+++ b/lib/api/entities.rb
@@ -135,10 +135,13 @@ module API
expose :custom_attributes, using: 'API::Entities::CustomAttribute', if: :with_custom_attributes
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)`
+ # MR describing the solution: https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/20555
projects_relation.preload(:project_feature, :route)
- .preload(:import_state)
- .preload(namespace: [:route, :owner],
- tags: :taggings)
+ .preload(:import_state, :tags)
+ .preload(namespace: [:route, :owner])
end
end
@@ -212,11 +215,15 @@ module API
expose :statistics, using: 'API::Entities::ProjectStatistics', if: :statistics
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)`
+ # MR describing the solution: https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/20555
super(projects_relation).preload(:group)
.preload(project_group_links: :group,
fork_network: :root_project,
forked_project_link: :forked_from_project,
- forked_from_project: [:route, :forks, namespace: :route, tags: :taggings])
+ forked_from_project: [:route, :forks, :tags, namespace: :route])
end
def self.forks_counting_projects(projects_relation)