elasticsearch-rails
elasticsearch-rails copied to clipboard
Improve ES::Model README suggestion for async indexing with after_save_commit
I got a lot of test failures using the original suggestion. First because newly created records weren't yet committed when the (test) worker ran, so I switched to after_commit
. But after_commit
also fires on destroy, so it would fail trying to reindex destroyed records. Rails 6 introduces after_save_commit
for this purpose. Prior to Rails 6 it would be after_commit ..., on: [:create, :update]
, but if you needed to change the next line to after_commit ..., on: :destroy
the latter callback would clobber the former, and this prevents that.
❌ Author of the following commits did not sign a Contributor Agreement: 9fec676677e1ba0dfc89b7df12d099b5bca7e319
Please, read and sign the above mentioned agreement if you want to contribute to this project