This PR implements proof of concept for new Chewy strategy. The strategy allows to avoid synchronous evaluation of index queries. Instead all the callbacks will be saved in class attribute and model type and id will be stashed into strategy instance. When strategy block ends it will enqueue IndicesUpdateWorker Sidekiq job with serialized stash as argument. The job will load records and run all the callbacks within sidekiq strategy block, which in turn will enqueue Sidekiq jobs updating indices.
Since we cannot schedule IndicesUpdateWorker job for destroyed records, instead all the callbacks will be run synchronously and resulted index types and ids will be stashed into strategy instance and run on the lazy_sidekiq strategy block end like if they would be run on the end of sidekiq strategy block.
Some concerns to consider:
One cannot rely on state within update_index blocks because record will be reinstantiated on the time when callbacks will be run. We can however serialize changes and previous_changes to Sidekiq jobs, or even specify what to serialize.
Before submitting the PR make sure the following are checked:
[x] The PR relates to only one subject with a clear title and description in grammatically correct, complete sentences.
This PR implements proof of concept for new Chewy strategy. The strategy allows to avoid synchronous evaluation of index queries. Instead all the callbacks will be saved in class attribute and model type and id will be stashed into strategy instance. When strategy block ends it will enqueue
IndicesUpdateWorker
Sidekiq job with serialized stash as argument. The job will load records and run all the callbacks withinsidekiq
strategy block, which in turn will enqueue Sidekiq jobs updating indices. Since we cannot scheduleIndicesUpdateWorker
job for destroyed records, instead all the callbacks will be run synchronously and resulted index types and ids will be stashed into strategy instance and run on thelazy_sidekiq
strategy block end like if they would be run on the end ofsidekiq
strategy block.Some concerns to consider:
update_index
blocks because record will be reinstantiated on the time when callbacks will be run. We can however serializechanges
andprevious_changes
to Sidekiq jobs, or even specify what to serialize.Before submitting the PR make sure the following are checked:
[Fix #issue-number]
(if the related issue exists).master
(if not - rebase it).