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
Boxiang Sun
gitlab-ce
Commits
7d91984c
Commit
7d91984c
authored
Jun 19, 2018
by
Michael Kozono
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Avoid N+1 queries while processing uploads
parent
1a426b04
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
9 deletions
+38
-9
lib/gitlab/verify/uploads.rb
lib/gitlab/verify/uploads.rb
+1
-1
spec/lib/gitlab/verify/uploads_spec.rb
spec/lib/gitlab/verify/uploads_spec.rb
+37
-8
No files found.
lib/gitlab/verify/uploads.rb
View file @
7d91984c
...
@@ -12,7 +12,7 @@ module Gitlab
...
@@ -12,7 +12,7 @@ module Gitlab
private
private
def
all_relation
def
all_relation
Upload
.
all
Upload
.
all
.
preload
(
:model
)
end
end
def
local?
(
upload
)
def
local?
(
upload
)
...
...
spec/lib/gitlab/verify/uploads_spec.rb
View file @
7d91984c
...
@@ -47,6 +47,10 @@ describe Gitlab::Verify::Uploads do
...
@@ -47,6 +47,10 @@ describe Gitlab::Verify::Uploads do
before
do
before
do
stub_uploads_object_storage
(
AvatarUploader
)
stub_uploads_object_storage
(
AvatarUploader
)
upload
.
update!
(
store:
ObjectStorage
::
Store
::
REMOTE
)
upload
.
update!
(
store:
ObjectStorage
::
Store
::
REMOTE
)
end
describe
'returned hash object'
do
before
do
expect
(
CarrierWave
::
Storage
::
Fog
::
File
).
to
receive
(
:new
).
and_return
(
file
)
expect
(
CarrierWave
::
Storage
::
Fog
::
File
).
to
receive
(
:new
).
and_return
(
file
)
end
end
...
@@ -63,5 +67,30 @@ describe Gitlab::Verify::Uploads do
...
@@ -63,5 +67,30 @@ describe Gitlab::Verify::Uploads do
expect
(
failure
).
to
include
(
'Remote object does not exist'
)
expect
(
failure
).
to
include
(
'Remote object does not exist'
)
end
end
end
end
describe
'performance'
do
before
do
allow
(
file
).
to
receive
(
:exists?
)
allow
(
CarrierWave
::
Storage
::
Fog
::
File
).
to
receive
(
:new
).
and_return
(
file
)
end
it
"avoids N+1 queries"
do
control_count
=
ActiveRecord
::
QueryRecorder
.
new
{
perform_task
}
# Create additional uploads in object storage
projects
=
create_list
(
:project
,
3
,
:with_avatar
)
uploads
=
projects
.
flat_map
(
&
:uploads
)
uploads
.
each
do
|
upload
|
upload
.
update!
(
store:
ObjectStorage
::
Store
::
REMOTE
)
end
expect
{
perform_task
}.
not_to
exceed_query_limit
(
control_count
)
end
def
perform_task
described_class
.
new
(
batch_size:
100
).
run_batches
{
}
end
end
end
end
end
end
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