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
70534bc5
Commit
70534bc5
authored
Aug 28, 2020
by
Terri Chu
Committed by
Douglas Barbosa Alexandre
Aug 28, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
RUN AS-IF-FOSS Fix group search users scope times out
parent
95a8b847
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
35 additions
and
11 deletions
+35
-11
changelogs/unreleased/31092-user-search-filtered-to-group-times-out.yml
...eleased/31092-user-search-filtered-to-group-times-out.yml
+5
-0
lib/gitlab/group_search_results.rb
lib/gitlab/group_search_results.rb
+14
-10
spec/lib/gitlab/group_search_results_spec.rb
spec/lib/gitlab/group_search_results_spec.rb
+16
-1
No files found.
changelogs/unreleased/31092-user-search-filtered-to-group-times-out.yml
0 → 100644
View file @
70534bc5
---
title
:
Improve group search users scope performance
merge_request
:
38701
author
:
type
:
performance
lib/gitlab/group_search_results.rb
View file @
70534bc5
...
@@ -12,20 +12,24 @@ module Gitlab
...
@@ -12,20 +12,24 @@ module Gitlab
# rubocop:disable CodeReuse/ActiveRecord
# rubocop:disable CodeReuse/ActiveRecord
def
users
def
users
# 1: get all groups the current user has access to
# get all groups the current user has access to
groups
=
GroupsFinder
.
new
(
current_user
).
execute
.
joins
(
:users
)
# ignore order inherited from GroupsFinder to improve performance
current_user_groups
=
GroupsFinder
.
new
(
current_user
).
execute
.
unscope
(
:order
)
#
2: Get the group's whole hierarchy
#
the hierarchy of the current group
group_
users
=
@group
.
direct_and_indirect_users
group_
groups
=
@group
.
self_and_hierarchy
.
unscope
(
:order
)
# 3: get all users the current user has access to (->
# the groups where the above hierarchies intersect
# `SearchResults#users`), which also applies the query.
intersect_groups
=
group_groups
.
where
(
id:
current_user_groups
)
# members of @group hierarchy where the user has access to the groups
members
=
GroupMember
.
where
(
group:
intersect_groups
).
non_invite
# get all users the current user has access to (-> `SearchResults#users`), which also applies the query
users
=
super
users
=
super
# 4: filter for users that belong to the previously selected groups
# filter users that belong to the previously selected groups
users
users
.
where
(
id:
members
.
select
(
:user_id
))
.
where
(
id:
group_users
.
select
(
'id'
))
.
where
(
id:
groups
.
select
(
'members.user_id'
))
end
end
# rubocop:enable CodeReuse/ActiveRecord
# rubocop:enable CodeReuse/ActiveRecord
...
...
spec/lib/gitlab/group_search_results_spec.rb
View file @
70534bc5
...
@@ -3,8 +3,10 @@
...
@@ -3,8 +3,10 @@
require
'spec_helper'
require
'spec_helper'
RSpec
.
describe
Gitlab
::
GroupSearchResults
do
RSpec
.
describe
Gitlab
::
GroupSearchResults
do
# group creation calls GroupFinder, so need to create the group
# before so expect(GroupsFinder) check works
let_it_be
(
:group
)
{
create
(
:group
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:group
)
{
create
(
:group
)
}
subject
(
:results
)
{
described_class
.
new
(
user
,
'gob'
,
anything
,
group:
group
)
}
subject
(
:results
)
{
described_class
.
new
(
user
,
'gob'
,
anything
,
group:
group
)
}
...
@@ -60,6 +62,19 @@ RSpec.describe Gitlab::GroupSearchResults do
...
@@ -60,6 +62,19 @@ RSpec.describe Gitlab::GroupSearchResults do
is_expected
.
to
be_empty
is_expected
.
to
be_empty
end
end
it
'does not return the user invited to the group'
do
user
=
create
(
:user
,
username:
'gob_bluth'
)
create
(
:group_member
,
:invited
,
:developer
,
user:
user
,
group:
group
)
is_expected
.
to
be_empty
end
it
'calls GroupFinder during execution'
do
expect
(
GroupsFinder
).
to
receive
(
:new
).
with
(
user
).
and_call_original
subject
end
end
end
describe
"#issuable_params"
do
describe
"#issuable_params"
do
...
...
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