Class: Mongoid::Report::Batches
- Inherits:
-
Struct
- Object
- Struct
- Mongoid::Report::Batches
- Defined in:
- lib/mongoid/report/batches.rb
Overview
Split the queries into threads.
Constant Summary collapse
- DEFAULT_THREAD_POOL_SIZE =
5
Instance Attribute Summary collapse
-
#conditions ⇒ Object
Returns the value of attribute conditions.
-
#settings ⇒ Object
Returns the value of attribute settings.
Instance Method Summary collapse
- #field ⇒ Object
-
#initialize(settings = {}, conditions = {}) ⇒ Batches
constructor
A new instance of Batches.
- #map ⇒ Object
- #present? ⇒ Boolean
- #range ⇒ Object
- #size ⇒ Object
Constructor Details
#initialize(settings = {}, conditions = {}) ⇒ Batches
8 9 10 11 12 13 14 |
# File 'lib/mongoid/report/batches.rb', line 8 def initialize(settings = {}, conditions = {}) if settings.nil? || settings.empty? settings = { 'pool_size' => DEFAULT_THREAD_POOL_SIZE } end super(settings, conditions) end |
Instance Attribute Details
#conditions ⇒ Object
Returns the value of attribute conditions
5 6 7 |
# File 'lib/mongoid/report/batches.rb', line 5 def conditions @conditions end |
#settings ⇒ Object
Returns the value of attribute settings
5 6 7 |
# File 'lib/mongoid/report/batches.rb', line 5 def settings @settings end |
Instance Method Details
#field ⇒ Object
16 17 18 |
# File 'lib/mongoid/report/batches.rb', line 16 def field conditions.keys[0] end |
#map ⇒ Object
24 25 26 27 28 |
# File 'lib/mongoid/report/batches.rb', line 24 def map range.each_slice(size.ceil).map do |r| yield r end end |
#present? ⇒ Boolean
34 35 36 37 |
# File 'lib/mongoid/report/batches.rb', line 34 def present? settings['pool_size'].present? && conditions.present? end |
#range ⇒ Object
20 21 22 |
# File 'lib/mongoid/report/batches.rb', line 20 def range conditions.values[0] end |
#size ⇒ Object
30 31 32 |
# File 'lib/mongoid/report/batches.rb', line 30 def size range.count.to_f / settings['pool_size'].to_f end |