scout-extended icon indicating copy to clipboard operation
scout-extended copied to clipboard

Why is the Record deleted before updating?

Open finalgamer opened this issue 6 years ago • 5 comments

In https://github.com/algolia/scout-extended/blob/db5bd4135c66738b79450d20fc6368a97fc8175e/src/Jobs/UpdateJob.php#L137 a request to delete the object from the search index is sent. One line below is the actual updateObject action, which is sent to Algolia.

Why is the object deleted before the update?

Due to this every update does also trigger a delete query doubling the amount of operations made on the index and basically doubling the cost of the Algolia subscription.

finalgamer avatar Sep 16 '19 10:09 finalgamer

Normally, we just send a delete if there is something that needs to be deleted: https://github.com/algolia/scout-extended/blob/db5bd4135c66738b79450d20fc6368a97fc8175e/src/Jobs/DeleteJob.php#L49.

Do you have a use case where you are being impacted by this? If yes, can you detail it?

nunomaduro avatar Sep 16 '19 10:09 nunomaduro

I have done some more digging and found that this is caused by my Eloquent Model having a splitter for a property.

For a more concrete example. We are storing news articles which may have a body property larger than the Algolia index size. Because of that we do split the body just before the limit is reached. Which most of our bodies do not reach, which means they are not split in multiple records.

I assume your intention with deleting the records is to ensure all split records are up to date. If this is the case is there a way to reduce this to one operation?

finalgamer avatar Sep 16 '19 11:09 finalgamer

@finalgamer You described perfectly the implementation. Is exactly that.

We don't have nothing in place to reduce this to one operation. Any ideas?

nunomaduro avatar Sep 16 '19 12:09 nunomaduro

My workaround would be to store the amount of records it generates in the database with the model and when updating the record the new count and last count are compared.

  • If the count is the same, only execute update.
  • If the new count is more, only execute update.
  • If the new count is less, execute delete and update.

My other workaround, which might work in my case, is to remove the splitting again and deal with incomplete search data on large articles.

finalgamer avatar Sep 16 '19 12:09 finalgamer

My workaround would be to store the amount of records it generates in the database with the model and when updating the record the new count and last count are compared.

Would be willing to code and add this feature?

nunomaduro avatar Sep 16 '19 13:09 nunomaduro