Class: Gitlab::Database::Count::ReltuplesCountStrategy

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/database/count/reltuples_count_strategy.rb

Overview

This strategy counts based on PostgreSQL’s statistics in pg_stat_user_tables.

Specifically, it relies on the column reltuples in said table. An additional check is performed to make sure statistics were updated within the last hour.

Otherwise, this strategy skips tables with outdated statistics.

There are no guarantees with respect to the accuracy of this strategy. Runtime however is guaranteed to be “fast”, because it only looks up statistics.

Direct Known Subclasses

TablesampleCountStrategy

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(models) ⇒ ReltuplesCountStrategy

Returns a new instance of ReltuplesCountStrategy.



18
19
20
# File 'lib/gitlab/database/count/reltuples_count_strategy.rb', line 18

def initialize(models)
  @models = models
end

Instance Attribute Details

#modelsObject (readonly)

Returns the value of attribute models.



16
17
18
# File 'lib/gitlab/database/count/reltuples_count_strategy.rb', line 16

def models
  @models
end

Instance Method Details

#countObject

Returns a hash of the table names that have recently updated tuples.



25
26
27
28
29
# File 'lib/gitlab/database/count/reltuples_count_strategy.rb', line 25

def count
  size_estimates
rescue *CONNECTION_ERRORS
  {}
end