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
847c698b
Commit
847c698b
authored
Aug 06, 2018
by
Imre Farkas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Optimize querying User#manageable_groups
parent
ad570fa6
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
14 deletions
+10
-14
app/models/user.rb
app/models/user.rb
+5
-14
changelogs/unreleased/ce-5666-optimize_querying_manageable_groups.yml
...nreleased/ce-5666-optimize_querying_manageable_groups.yml
+5
-0
No files found.
app/models/user.rb
View file @
847c698b
...
...
@@ -101,6 +101,10 @@ class User < ActiveRecord::Base
has_many
:groups
,
through: :group_members
has_many
:owned_groups
,
->
{
where
(
members:
{
access_level:
Gitlab
::
Access
::
OWNER
})
},
through: :group_members
,
source: :group
has_many
:maintainers_groups
,
->
{
where
(
members:
{
access_level:
Gitlab
::
Access
::
MAINTAINER
})
},
through: :group_members
,
source: :group
has_many
:owned_or_maintainers_groups
,
->
{
where
(
members:
{
access_level:
[
Gitlab
::
Access
::
MAINTAINER
,
Gitlab
::
Access
::
OWNER
]
})
},
through: :group_members
,
source: :group
alias_attribute
:masters_groups
,
:maintainers_groups
# Projects
...
...
@@ -982,15 +986,7 @@ class User < ActiveRecord::Base
end
def
manageable_groups
union_sql
=
Gitlab
::
SQL
::
Union
.
new
([
owned_groups
.
select
(
:id
),
maintainers_groups
.
select
(
:id
)]).
to_sql
# Update this line to not use raw SQL when migrated to Rails 5.2.
# Either ActiveRecord or Arel constructions are fine.
# This was replaced with the raw SQL construction because of bugs in the arel gem.
# Bugs were fixed in arel 9.0.0 (Rails 5.2).
owned_and_maintainer_groups
=
Group
.
where
(
"namespaces.id IN (
#{
union_sql
}
)"
)
# rubocop:disable GitlabSecurity/SqlInjection
Gitlab
::
GroupHierarchy
.
new
(
owned_and_maintainer_groups
).
base_and_descendants
Gitlab
::
GroupHierarchy
.
new
(
owned_or_maintainers_groups
).
base_and_descendants
end
def
namespaces
...
...
@@ -1244,11 +1240,6 @@ class User < ActiveRecord::Base
!
terms_accepted?
end
def
owned_or_maintainers_groups
union
=
Gitlab
::
SQL
::
Union
.
new
([
owned_groups
,
maintainers_groups
])
Group
.
from
(
"(
#{
union
.
to_sql
}
) namespaces"
)
end
# @deprecated
alias_method
:owned_or_masters_groups
,
:owned_or_maintainers_groups
...
...
changelogs/unreleased/ce-5666-optimize_querying_manageable_groups.yml
0 → 100644
View file @
847c698b
---
title
:
Optimize querying User#manageable_groups
merge_request
:
21050
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