Commit f2ec9d2d authored by Andreas Brandl's avatar Andreas Brandl

Add ExactCountStrategy.

parent f3a93151
......@@ -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
......
......@@ -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
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment