2018-11-23 10:31:15 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
module Database
|
|
|
|
module Count
|
|
|
|
# This strategy performs an exact count on the model.
|
|
|
|
#
|
|
|
|
# This is guaranteed to be accurate, however it also scans the
|
|
|
|
# whole table. Hence, there are no guarantees with respect
|
|
|
|
# to runtime.
|
|
|
|
#
|
|
|
|
# Note that for very large tables, this may even timeout.
|
|
|
|
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
|
2018-12-06 11:07:14 -05:00
|
|
|
rescue *CONNECTION_ERRORS
|
|
|
|
{}
|
2018-11-23 10:31:15 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|