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
Léo-Paul Géneau
gitlab-ce
Commits
5f22dbdb
Commit
5f22dbdb
authored
Mar 22, 2018
by
Tiago Botelho
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improves User#owned_projects query performance
parent
40c338a4
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
3 deletions
+15
-3
app/models/user.rb
app/models/user.rb
+10
-3
changelogs/unreleased/43552-user-owned-projects-query-performance-improvement.yml
...552-user-owned-projects-query-performance-improvement.yml
+5
-0
No files found.
app/models/user.rb
View file @
5f22dbdb
...
...
@@ -623,9 +623,7 @@ class User < ActiveRecord::Base
end
def
owned_projects
@owned_projects
||=
Project
.
where
(
'namespace_id IN (?) OR namespace_id = ?'
,
owned_groups
.
select
(
:id
),
namespace
.
id
).
joins
(
:namespace
)
@owned_projects
||=
Project
.
from
(
"(
#{
owned_projects_union
.
to_sql
}
) AS projects"
)
end
# Returns projects which user can admin issues on (for example to move an issue to that project).
...
...
@@ -1196,6 +1194,15 @@ class User < ActiveRecord::Base
private
def
owned_projects_union
Gitlab
::
SQL
::
Union
.
new
([
Project
.
where
(
namespace:
namespace
),
Project
.
joins
(
:project_authorizations
)
.
where
(
"projects.namespace_id <> ?"
,
namespace
.
id
)
.
where
(
project_authorizations:
{
user_id:
id
,
access_level:
Gitlab
::
Access
::
OWNER
})
],
remove_duplicates:
false
)
end
def
ci_projects_union
scope
=
{
access_level:
[
Gitlab
::
Access
::
MASTER
,
Gitlab
::
Access
::
OWNER
]
}
groups
=
groups_projects
.
where
(
members:
scope
)
...
...
changelogs/unreleased/43552-user-owned-projects-query-performance-improvement.yml
0 → 100644
View file @
5f22dbdb
---
title
:
Improves the performance of projects list page
merge_request
:
17934
author
:
type
:
performance
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