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
f2ec9d2d
Commit
f2ec9d2d
authored
Oct 28, 2018
by
Andreas Brandl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add ExactCountStrategy.
parent
f3a93151
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
0 deletions
+23
-0
lib/gitlab/database/count.rb
lib/gitlab/database/count.rb
+13
-0
spec/lib/gitlab/database/count_spec.rb
spec/lib/gitlab/database/count_spec.rb
+10
-0
No files found.
lib/gitlab/database/count.rb
View file @
f2ec9d2d
...
...
@@ -57,6 +57,19 @@ module Gitlab
ReltuplesCountStrategy
.
new
(
table_names
).
count
end
class
ExactCountStrategy
attr_reader
:models
def
initialize
(
models
)
@models
=
models
end
def
count
models
.
each_with_object
({})
do
|
model
,
data
|
data
[
model
]
=
model
.
count
end
end
end
class
ReltuplesCountStrategy
attr_reader
:table_names
...
...
spec/lib/gitlab/database/count_spec.rb
View file @
f2ec9d2d
...
...
@@ -66,6 +66,16 @@ describe Gitlab::Database::Count do
expect
(
described_class
.
approximate_counts
(
models
)).
to
eq
({
Project
=>
3
,
Identity
=>
1
})
end
end
describe
Gitlab
::
Database
::
Count
::
ExactCountStrategy
do
subject
{
described_class
.
new
(
models
).
count
}
it
'counts all models'
do
models
.
each
{
|
model
|
expect
(
model
).
to
receive
(
:count
).
and_call_original
}
expect
(
subject
).
to
eq
({
Project
=>
3
,
Identity
=>
1
})
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