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
1e0673f9
Commit
1e0673f9
authored
Dec 04, 2019
by
Andreas Brandl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move prepare! into concern
parent
378e2345
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
15 deletions
+34
-15
lib/api/entities.rb
lib/api/entities.rb
+0
-8
lib/api/projects_batch_counting.rb
lib/api/projects_batch_counting.rb
+10
-2
spec/lib/api/projects_batch_counting_spec.rb
spec/lib/api/projects_batch_counting_spec.rb
+24
-5
No files found.
lib/api/entities.rb
View file @
1e0673f9
...
...
@@ -211,14 +211,6 @@ module API
expose
:namespace
,
using:
'API::Entities::NamespaceBasic'
expose
:custom_attributes
,
using:
'API::Entities::CustomAttribute'
,
if: :with_custom_attributes
# This adds preloading to the query and executes batch counting
# Side-effect: The query will be executed during batch counting
def
self
.
prepare!
(
projects_relation
)
preload_relation
(
projects_relation
).
tap
do
|
projects
|
execute_batch_counting
(
projects
)
end
end
# rubocop: disable CodeReuse/ActiveRecord
def
self
.
preload_relation
(
projects_relation
,
options
=
{})
# Preloading tags, should be done with using only `:tags`,
...
...
lib/api/projects_batch_counting.rb
View file @
1e0673f9
...
...
@@ -5,8 +5,12 @@ module API
extend
ActiveSupport
::
Concern
class_methods
do
def
forks_counting_projects
(
projects
)
projects
# This adds preloading to the query and executes batch counting
# Side-effect: The query will be executed during batch counting
def
prepare!
(
projects_relation
)
preload_relation
(
projects_relation
).
tap
do
|
projects
|
execute_batch_counting
(
projects
)
end
end
def
execute_batch_counting
(
projects
)
...
...
@@ -14,6 +18,10 @@ module API
::
Projects
::
BatchOpenIssuesCountService
.
new
(
projects
).
refresh_cache
end
def
forks_counting_projects
(
projects
)
projects
end
end
end
end
spec/lib/api/projects_batch_counting_spec.rb
View file @
1e0673f9
...
...
@@ -3,13 +3,32 @@
require
'spec_helper'
describe
API
::
ProjectsBatchCounting
do
describe
'.execute_batch_counting'
do
subject
do
Class
.
new
do
include
::
API
::
ProjectsBatchCounting
end
subject
do
Class
.
new
do
include
::
API
::
ProjectsBatchCounting
end
end
describe
'.prepare!'
do
let
(
:projects
)
{
double
}
let
(
:preloaded_projects
)
{
double
}
it
'preloads the relation'
do
expect
(
subject
).
to
receive
(
:preload_relation
).
with
(
projects
).
and_return
(
preloaded_projects
)
allow
(
subject
).
to
receive
(
:execute_batch_counting
).
with
(
preloaded_projects
)
expect
(
subject
.
prepare!
(
projects
)).
to
eq
(
preloaded_projects
)
end
it
'executes batch counting'
do
allow
(
subject
).
to
receive
(
:preload_relation
).
with
(
projects
).
and_return
(
preloaded_projects
)
expect
(
subject
).
to
receive
(
:execute_batch_counting
).
with
(
preloaded_projects
)
subject
.
prepare!
(
projects
)
end
end
describe
'.execute_batch_counting'
do
let
(
:projects
)
{
create_list
(
:project
,
2
)
}
let
(
:count_service
)
{
double
}
...
...
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