summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAndreas Brandl <abrandl@gitlab.com>2018-10-28 17:07:05 +0100
committerAndreas Brandl <abrandl@gitlab.com>2018-12-03 21:26:48 +0100
commitc5fb4682556d955ecbcbd589ffb18a95c7fbe0a1 (patch)
tree673cdc57d11c3aa80ffbb7acfb07612e603f0cd9 /lib
parentb6a530c9b14e0f7a1f7ea7717d68a105f4d43409 (diff)
downloadgitlab-ce-c5fb4682556d955ecbcbd589ffb18a95c7fbe0a1.tar.gz
Flexible approximate counts with fallback strategies.
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/database/count.rb32
1 files changed, 18 insertions, 14 deletions
diff --git a/lib/gitlab/database/count.rb b/lib/gitlab/database/count.rb
index 55f0cbd18be..beb5a8d3556 100644
--- a/lib/gitlab/database/count.rb
+++ b/lib/gitlab/database/count.rb
@@ -25,21 +25,17 @@ module Gitlab
#
# @param [Array]
# @return [Hash] of Model -> count mapping
- def self.approximate_counts(models)
- counts_by_model = {}
-
- if Gitlab::Database.postgresql?
- #counts_by_model = ReltuplesCountStrategy.new(models).count
- counts_by_model = reltuples_from_recently_updated(models)
- end
-
- missing_models = models - counts_by_model.keys
-
- ExactCountStrategy.new(missing_models).count.each do |model, count|
- counts_by_model[model] = count
+ def self.approximate_counts(models, strategies = [ReltuplesCountStrategy, ExactCountStrategy])
+ strategies.each_with_object({}) do |strategy, counts_by_model|
+ if strategy.enabled?
+ models_with_missing_counts = models - counts_by_model.keys
+ counts = strategy.new(models_with_missing_counts).count
+
+ counts.each do |model, count|
+ counts_by_model[model] = count
+ end
+ end
end
-
- counts_by_model
end
# Returns a hash of the table names that have recently updated tuples.
@@ -61,6 +57,10 @@ module Gitlab
data[model] = model.count
end
end
+
+ def self.enabled?
+ true
+ end
end
class ReltuplesCountStrategy
@@ -92,6 +92,10 @@ module Gitlab
{}
end
+ def self.enabled?
+ Gitlab::Database.postgresql?
+ end
+
private
def table_names