Class: Serega::SeregaBatch::AttributeLoaders
- Inherits:
-
Object
- Object
- Serega::SeregaBatch::AttributeLoaders
- Defined in:
- lib/serega/batch/attribute_loaders.rb
Overview
Batch loaders
Remembers data required to batch load all attributes
Instance Method Summary collapse
-
#add_objects(plan, objects) ⇒ void
Gathers a chunk of objects serialized at a plan level, so every attribute at that level shares one set of objects to batch load against.
-
#initialize(context) ⇒ AttributeLoaders
constructor
Initializes new batch loaders.
-
#load_all ⇒ Object
Loads all registered batches and attaches loaded values.
-
#remember(point, object, attacher) ⇒ void
Remembers data for batch serialization:.
Constructor Details
#initialize(context) ⇒ AttributeLoaders
Initializes new batch loaders
18 19 20 21 22 23 |
# File 'lib/serega/batch/attribute_loaders.rb', line 18 def initialize(context) @context = context @attribute_loaders = [] @point_index = {}.compare_by_identity @levels = {}.compare_by_identity end |
Instance Method Details
#add_objects(plan, objects) ⇒ void
This method returns an undefined value.
Gathers a chunk of objects serialized at a plan level, so every attribute at that level shares one set of objects to batch load against.
32 33 34 |
# File 'lib/serega/batch/attribute_loaders.rb', line 32 def add_objects(plan, objects) level_for(plan).add_objects(objects) end |
#load_all ⇒ Object
Loads all registered batches and attaches loaded values.
Iterates over each loader including loaders added during iteration (child serializers discovered inside a batch flush add new loaders).
61 62 63 64 65 66 67 68 |
# File 'lib/serega/batch/attribute_loaders.rb', line 61 def load_all i = 0 while i < attribute_loaders.size attribute_loader = attribute_loaders[i] attribute_loader.attach(load_batches(attribute_loader)) i += 1 end end |
#remember(point, object, attacher) ⇒ void
This method returns an undefined value.
Remembers data for batch serialization:
43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/serega/batch/attribute_loaders.rb', line 43 def remember(point, object, attacher) attribute_loader = point_index[point] unless attribute_loader serializer_class = point.class.serializer_class attribute_loader = serializer_class::SeregaBatchAttributeLoader.new(point, level_for(point.plan)) attribute_loaders << attribute_loader point_index[point] = attribute_loader end attribute_loader.store(object, attacher) end |