Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
heptapod
heptapod
Commits
bcb27922c1d9
Commit
b4301f64
authored
Oct 28, 2018
by
Andreas Brandl
Browse files
Add ExactCountStrategy.
parent
e5706c39405c
Changes
2
Hide whitespace changes
Inline
Side-by-side
lib/gitlab/database/count.rb
View file @
bcb27922
...
@@ -57,6 +57,19 @@ def self.reltuples_from_recently_updated(table_names)
...
@@ -57,6 +57,19 @@ def self.reltuples_from_recently_updated(table_names)
ReltuplesCountStrategy
.
new
(
table_names
).
count
ReltuplesCountStrategy
.
new
(
table_names
).
count
end
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
class
ReltuplesCountStrategy
attr_reader
:table_names
attr_reader
:table_names
...
...
spec/lib/gitlab/database/count_spec.rb
View file @
bcb27922
...
@@ -66,6 +66,16 @@
...
@@ -66,6 +66,16 @@
expect
(
described_class
.
approximate_counts
(
models
)).
to
eq
({
Project
=>
3
,
Identity
=>
1
})
expect
(
described_class
.
approximate_counts
(
models
)).
to
eq
({
Project
=>
3
,
Identity
=>
1
})
end
end
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
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