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.


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

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


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