Class: Gitlab::Database::Count::ExactCountStrategy
- Inherits:
-
Object
- Object
- Gitlab::Database::Count::ExactCountStrategy
- Defined in:
- lib/gitlab/database/count/exact_count_strategy.rb
Overview
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.
Instance Attribute Summary collapse
-
#models ⇒ Object
readonly
Returns the value of attribute models.
Instance Method Summary collapse
- #count ⇒ Object
-
#initialize(models) ⇒ ExactCountStrategy
constructor
A new instance of ExactCountStrategy.
Constructor Details
#initialize(models) ⇒ ExactCountStrategy
Returns a new instance of ExactCountStrategy.
15 16 17 |
# File 'lib/gitlab/database/count/exact_count_strategy.rb', line 15 def initialize(models) @models = models end |
Instance Attribute Details
#models ⇒ Object (readonly)
Returns the value of attribute models
14 15 16 |
# File 'lib/gitlab/database/count/exact_count_strategy.rb', line 14 def models @models end |
Instance Method Details
#count ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/gitlab/database/count/exact_count_strategy.rb', line 19 def count models.each_with_object({}) do |model, data| data[model] = model.count end rescue *CONNECTION_ERRORS {} end |