Class: Chewy::Strategy::Atomic
- Defined in:
- lib/chewy/strategy/atomic.rb
Overview
This strategy accomulates all the objects prepared for indexing and fires index process when strategy is popped from the strategies stack.
Chewy.strategy(:atomic) do
User.all.map(&:save) # Does nothing here
Post.all.map(&:save) # And here
# It imports all the changed users and posts right here
# before block leaving with bulk ES API, kinda optimization
end
Instance Method Summary collapse
-
#initialize ⇒ Atomic
constructor
A new instance of Atomic.
- #leave ⇒ Object
- #update(type, objects, options = {}) ⇒ Object
Methods inherited from Base
Constructor Details
#initialize ⇒ Atomic
15 16 17 |
# File 'lib/chewy/strategy/atomic.rb', line 15 def initialize @stash = {} end |
Instance Method Details
#leave ⇒ Object
26 27 28 |
# File 'lib/chewy/strategy/atomic.rb', line 26 def leave @stash.all? { |type, ids| type.import!(ids) } end |
#update(type, objects, options = {}) ⇒ Object
19 20 21 22 23 24 |
# File 'lib/chewy/strategy/atomic.rb', line 19 def update type, objects, = {} ActiveSupport::Deprecation.warn("`urgent: true` option is deprecated and is not effective inside `:atomic` strategy, use `Chewy.strategy(:urgent)` strategy instead") if .key?(:urgent) @stash[type] ||= [] @stash[type] |= type.adapter.identify(objects) end |