Class: Gitlab::Database::Count::ExactCountStrategy

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(models) ⇒ ExactCountStrategy

Returns a new instance of ExactCountStrategy.



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

def initialize(models)
  @models = models
end

Instance Attribute Details

#modelsObject (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

#countObject



20
21
22
23
24
# File 'lib/gitlab/database/count/exact_count_strategy.rb', line 20

def count
  models.index_with(&:count)
rescue *CONNECTION_ERRORS
  {}
end