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.


21
22
23
# File 'lib/gitlab/database/count/reltuples_count_strategy.rb', line 21

def initialize(models)
  @models = models
end

Instance Attribute Details

#modelsObject (readonly)

Returns the value of attribute models


20
21
22
# File 'lib/gitlab/database/count/reltuples_count_strategy.rb', line 20

def models
  @models
end

Instance Method Details

#countObject

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


28
29
30
31
32
# File 'lib/gitlab/database/count/reltuples_count_strategy.rb', line 28

def count
  size_estimates
rescue *CONNECTION_ERRORS
  {}
end