diff options
author | Yorick Peterse <yorickpeterse@gmail.com> | 2018-07-12 16:50:08 +0300 |
---|---|---|
committer | Yorick Peterse <yorickpeterse@gmail.com> | 2018-07-12 16:50:08 +0300 |
commit | 5a55dd9936ad1d5c2471ef246b17c4a9a428e6b7 (patch) | |
tree | 4866717df34516c5a907dac3e21fdab2939ff4d3 /lib/api | |
parent | d5e53119ce8654f36ca64fd8fc972227862de1e8 (diff) | |
parent | 1399eb058bfe22dc3fac5ee464e25ea67dd9e59d (diff) |
Merge branch 'fix-performance-problem-of-tags-query' into 'master'
Fix performance problem of tags query
Closes gitlab-com/infrastructure#4550
See merge request gitlab-org/gitlab-ce!20555
Diffstat (limited to 'lib/api')
-rw-r--r-- | lib/api/entities.rb | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/lib/api/entities.rb b/lib/api/entities.rb index 66b62d9ee2e..b256c33c631 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) |