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
7e3c5aa3
Commit
7e3c5aa3
authored
Jun 05, 2020
by
Adam Hegyi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Optimize participants list
parent
156c3306
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
2 deletions
+39
-2
app/models/members/group_member.rb
app/models/members/group_member.rb
+8
-1
spec/models/members/group_member_spec.rb
spec/models/members/group_member_spec.rb
+31
-1
No files found.
app/models/members/group_member.rb
View file @
7e3c5aa3
...
@@ -16,9 +16,16 @@ class GroupMember < Member
...
@@ -16,9 +16,16 @@ class GroupMember < Member
default_scope
{
where
(
source_type:
SOURCE_TYPE
)
}
default_scope
{
where
(
source_type:
SOURCE_TYPE
)
}
scope
:of_groups
,
->
(
groups
)
{
where
(
source_id:
groups
.
select
(
:id
))
}
scope
:of_groups
,
->
(
groups
)
{
where
(
source_id:
groups
.
select
(
:id
))
}
scope
:count_users_by_group_id
,
->
{
joins
(
:user
).
group
(
:source_id
).
count
}
scope
:of_ldap_type
,
->
{
where
(
ldap:
true
)
}
scope
:of_ldap_type
,
->
{
where
(
ldap:
true
)
}
scope
:count_users_by_group_id
,
->
do
if
Feature
.
enabled?
(
:optimized_count_users_by_group_id
)
group
(
:source_id
).
count
else
joins
(
:user
).
group
(
:source_id
).
count
end
end
after_create
:update_two_factor_requirement
,
unless: :invite?
after_create
:update_two_factor_requirement
,
unless: :invite?
after_destroy
:update_two_factor_requirement
,
unless: :invite?
after_destroy
:update_two_factor_requirement
,
unless: :invite?
...
...
spec/models/members/group_member_spec.rb
View file @
7e3c5aa3
...
@@ -4,7 +4,7 @@ require 'spec_helper'
...
@@ -4,7 +4,7 @@ require 'spec_helper'
describe
GroupMember
do
describe
GroupMember
do
context
'scopes'
do
context
'scopes'
do
describe
'.count_users_by_group_id'
do
shared_examples
'.count_users_by_group_id'
do
it
'counts users by group ID'
do
it
'counts users by group ID'
do
user_1
=
create
(
:user
)
user_1
=
create
(
:user
)
user_2
=
create
(
:user
)
user_2
=
create
(
:user
)
...
@@ -20,6 +20,36 @@ describe GroupMember do
...
@@ -20,6 +20,36 @@ describe GroupMember do
end
end
end
end
describe
'.count_users_by_group_id with optimized_count_users_by_group_id feature flag on'
do
before
do
stub_feature_flags
(
optimized_count_users_by_group_id:
true
)
end
it_behaves_like
'.count_users_by_group_id'
it
'does not JOIN users'
do
scope
=
described_class
.
all
expect
(
scope
).
not_to
receive
(
:joins
).
with
(
:user
)
scope
.
count_users_by_group_id
end
end
describe
'.count_users_by_group_id with optimized_count_users_by_group_id feature flag off'
do
before
do
stub_feature_flags
(
optimized_count_users_by_group_id:
false
)
end
it_behaves_like
'.count_users_by_group_id'
it
'does JOIN users'
do
scope
=
described_class
.
all
expect
(
scope
).
to
receive
(
:joins
).
with
(
:user
).
and_call_original
scope
.
count_users_by_group_id
end
end
describe
'.of_ldap_type'
do
describe
'.of_ldap_type'
do
it
'returns ldap type users'
do
it
'returns ldap type users'
do
group_member
=
create
(
:group_member
,
:ldap
)
group_member
=
create
(
:group_member
,
:ldap
)
...
...
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