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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
66d48385
Commit
66d48385
authored
Jul 29, 2019
by
🙈 jacopo beschi 🙉
Committed by
Mayra Cabrera
Jul 29, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Resolve "MembersFinder contains slow database query with OR conditions"
parent
18e3dcc6
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
13 additions
and
6 deletions
+13
-6
app/finders/group_members_finder.rb
app/finders/group_members_finder.rb
+6
-6
app/models/members/group_member.rb
app/models/members/group_member.rb
+2
-0
changelogs/unreleased/64180-membersfinder-contains-slow-database-query-with-or-conditions.yml
...inder-contains-slow-database-query-with-or-conditions.yml
+5
-0
No files found.
app/finders/group_members_finder.rb
View file @
66d48385
# frozen_string_literal: true
# frozen_string_literal: true
class
GroupMembersFinder
class
GroupMembersFinder
<
UnionFinder
def
initialize
(
group
)
def
initialize
(
group
)
@group
=
group
@group
=
group
end
end
...
@@ -8,18 +8,18 @@ class GroupMembersFinder
...
@@ -8,18 +8,18 @@ class GroupMembersFinder
# rubocop: disable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def
execute
(
include_descendants:
false
)
def
execute
(
include_descendants:
false
)
group_members
=
@group
.
members
group_members
=
@group
.
members
where
s
=
[]
relation
s
=
[]
return
group_members
unless
@group
.
parent
||
include_descendants
return
group_members
unless
@group
.
parent
||
include_descendants
wheres
<<
"members.id IN (
#{
group_members
.
select
(
:id
).
to_sql
}
)"
relations
<<
group_members
if
@group
.
parent
if
@group
.
parent
parents_members
=
GroupMember
.
non_request
parents_members
=
GroupMember
.
non_request
.
where
(
source_id:
@group
.
ancestors
.
select
(
:id
))
.
where
(
source_id:
@group
.
ancestors
.
select
(
:id
))
.
where
.
not
(
user_id:
@group
.
users
.
select
(
:id
))
.
where
.
not
(
user_id:
@group
.
users
.
select
(
:id
))
wheres
<<
"members.id IN (
#{
parents_members
.
select
(
:id
).
to_sql
}
)"
relations
<<
parents_members
end
end
if
include_descendants
if
include_descendants
...
@@ -27,10 +27,10 @@ class GroupMembersFinder
...
@@ -27,10 +27,10 @@ class GroupMembersFinder
.
where
(
source_id:
@group
.
descendants
.
select
(
:id
))
.
where
(
source_id:
@group
.
descendants
.
select
(
:id
))
.
where
.
not
(
user_id:
@group
.
users
.
select
(
:id
))
.
where
.
not
(
user_id:
@group
.
users
.
select
(
:id
))
wheres
<<
"members.id IN (
#{
descendant_members
.
select
(
:id
).
to_sql
}
)"
relations
<<
descendant_members
end
end
GroupMember
.
where
(
wheres
.
join
(
' OR '
)
)
find_union
(
relations
,
GroupMember
)
end
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: enable CodeReuse/ActiveRecord
end
end
app/models/members/group_member.rb
View file @
66d48385
# frozen_string_literal: true
# frozen_string_literal: true
class
GroupMember
<
Member
class
GroupMember
<
Member
include
FromUnion
SOURCE_TYPE
=
'Namespace'
.
freeze
SOURCE_TYPE
=
'Namespace'
.
freeze
belongs_to
:group
,
foreign_key:
'source_id'
belongs_to
:group
,
foreign_key:
'source_id'
...
...
changelogs/unreleased/64180-membersfinder-contains-slow-database-query-with-or-conditions.yml
0 → 100644
View file @
66d48385
---
title
:
Improve MembersFinder query performance using UNION
merge_request
:
30451
author
:
Jacopo Beschi @jacopo-beschi
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