wp-search-with-algolia icon indicating copy to clipboard operation
wp-search-with-algolia copied to clipboard

Post being deleted in Algolia when updated

Open simpledeploy opened this issue 8 months ago • 1 comments

Describe the bug We have had problems with posts being deleted from Algolia indexes on update, both when the editors updates post via WP Admin and also by using $algolia->get_index('posts_poi')->sync($post) which we are using for batch updating of posts.

We disabled the async update to avoid race conditions by this filter: add_filter('algolia_should_wait_on_delete_item', '__return_true');

It seems to have improved, but we are still occasionally see this issues. When inspecting the Algolia API log for those instances, we can see that the time stamp for both delete and update are identically.

What can we expect from the algolia_should_wait_on_delete_item filter.

To Reproduce Steps to reproduce the behavior:

  1. Enabled the the filter add_filter('algolia_should_wait_on_delete_item', '__return_true');
  2. Make updates to posts
  3. Inspect the Algolia API Log and occasionally you will see that update and delete requests have the same timestamp, sometimes this leads to race conditions and the post is deleted from Algolia.

Expected behavior No race conditions and deletions of posts in Algolia with the algolia_should_wait_on_delete_item filter enabled.

Screenshots

Image Image

simpledeploy avatar Jun 23 '25 08:06 simpledeploy

That filter essentially has our code making use of

$this->get_index()->deleteObjects( $object_ids )->wait();

instead of

$this->get_index()->deleteObjects( $object_ids );

which is part of Algolia's PHP client. It makes things a more synchronous, instead of asynchronous.

Why it's still having some race-like conditions, I'm not completely sure.

tw2113 avatar Jun 23 '25 13:06 tw2113