Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
gitlab-ce
Commits
1399eb05
Commit
1399eb05
authored
Jul 11, 2018
by
Kamil Trzciński
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix performance problem of accessing tag list for projects api endpoints
parent
67157de1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
4 deletions
+16
-4
changelogs/unreleased/fix-performance-problem-of-tags-query.yml
...logs/unreleased/fix-performance-problem-of-tags-query.yml
+5
-0
lib/api/entities.rb
lib/api/entities.rb
+11
-4
No files found.
changelogs/unreleased/fix-performance-problem-of-tags-query.yml
0 → 100644
View file @
1399eb05
---
title
:
Fix performance problem of accessing tag list for projects api endpoints
merge_request
:
author
:
type
:
performance
lib/api/entities.rb
View file @
1399eb05
...
@@ -135,10 +135,13 @@ module API
...
@@ -135,10 +135,13 @@ module API
expose
:custom_attributes
,
using:
'API::Entities::CustomAttribute'
,
if: :with_custom_attributes
expose
:custom_attributes
,
using:
'API::Entities::CustomAttribute'
,
if: :with_custom_attributes
def
self
.
preload_relation
(
projects_relation
,
options
=
{})
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
)
projects_relation
.
preload
(
:project_feature
,
:route
)
.
preload
(
:import_state
)
.
preload
(
:import_state
,
:tags
)
.
preload
(
namespace:
[
:route
,
:owner
],
.
preload
(
namespace:
[
:route
,
:owner
])
tags: :taggings
)
end
end
end
end
...
@@ -212,11 +215,15 @@ module API
...
@@ -212,11 +215,15 @@ module API
expose
:statistics
,
using:
'API::Entities::ProjectStatistics'
,
if: :statistics
expose
:statistics
,
using:
'API::Entities::ProjectStatistics'
,
if: :statistics
def
self
.
preload_relation
(
projects_relation
,
options
=
{})
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
)
super
(
projects_relation
).
preload
(
:group
)
.
preload
(
project_group_links: :group
,
.
preload
(
project_group_links: :group
,
fork_network: :root_project
,
fork_network: :root_project
,
forked_project_link: :forked_from_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
end
def
self
.
forks_counting_projects
(
projects_relation
)
def
self
.
forks_counting_projects
(
projects_relation
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment