Class: Gitlab::Database::Count::ReltuplesCountStrategy
- Inherits:
-
Object
- Object
- Gitlab::Database::Count::ReltuplesCountStrategy
- 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
Instance Attribute Summary collapse
-
#models ⇒ Object
readonly
Returns the value of attribute models.
Instance Method Summary collapse
-
#count ⇒ Object
Returns a hash of the table names that have recently updated tuples.
-
#initialize(models) ⇒ ReltuplesCountStrategy
constructor
A new instance of ReltuplesCountStrategy.
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
#models ⇒ Object (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
#count ⇒ Object
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 |