BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
b8dc4c76
Unverified
Commit
b8dc4c76
authored
Apr 28, 2017
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Collect all users by single query when using Member#add_users
Signed-off-by:
Dmitriy Zaporozhets
<
dmitriy.zaporozhets@gmail.com
>
parent
00e4ec55
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
2 deletions
+9
-2
member.rb
app/models/member.rb
+5
-0
member_spec.rb
spec/models/member_spec.rb
+4
-2
No files found.
app/models/member.rb
View file @
b8dc4c76
...
...
@@ -154,6 +154,11 @@ class Member < ActiveRecord::Base
def
add_users
(
source
,
users
,
access_level
,
current_user:
nil
,
expires_at:
nil
)
return
[]
unless
users
.
present?
# Collect all user ids into separate array
# so we can use single sql query to get user objects
user_ids
=
users
.
select
{
|
user
|
user
=~
/\A\d+\Z/
}
users
=
users
-
user_ids
+
User
.
where
(
id:
user_ids
)
self
.
transaction
do
users
.
map
do
|
user
|
add_user
(
...
...
spec/models/member_spec.rb
View file @
b8dc4c76
...
...
@@ -390,13 +390,15 @@ describe Member, models: true do
%w[project group]
.
each
do
|
source_type
|
context
"when source is a
#{
source_type
}
"
do
let!
(
:source
)
{
create
(
source_type
,
:public
,
:access_requestable
)
}
let!
(
:user
)
{
create
(
:user
)
}
let!
(
:admin
)
{
create
(
:admin
)
}
let
(
:user1
)
{
create
(
:user
)
}
let
(
:user2
)
{
create
(
:user
)
}
it
'returns a <Source>Member objects'
do
members
=
described_class
.
add_users
(
source
,
[
user
],
:master
)
members
=
described_class
.
add_users
(
source
,
[
user
1
,
user2
],
:master
)
expect
(
members
).
to
be_a
Array
expect
(
members
.
size
).
to
eq
(
2
)
expect
(
members
.
first
).
to
be_a
"
#{
source_type
.
classify
}
Member"
.
constantize
expect
(
members
.
first
).
to
be_persisted
end
...
...
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