debian-mirror-gitlab/lib/gitlab/database/count/exact_count_strategy.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

29 lines
647 B
Ruby
Raw Normal View History

2019-02-15 15:39:39 +05:30
# 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
2022-05-07 20:08:51 +05:30
2019-02-15 15:39:39 +05:30
def initialize(models)
@models = models
end
def count
2023-03-04 22:38:38 +05:30
models.index_with(&:count)
2019-02-15 15:39:39 +05:30
rescue *CONNECTION_ERRORS
{}
end
end
end
end
end