strapi-plugin-meilisearch icon indicating copy to clipboard operation
strapi-plugin-meilisearch copied to clipboard

Batch delete documents instead of deleting them one by one in update lifecycle.

Open bidoubiwa opened this issue 2 years ago • 1 comments

See #611

Currently when you update multiple entries, it trigger the afterUpdateMany lifecycle.

https://github.com/meilisearch/strapi-plugin-meilisearch/blob/f322bec2a5cc15ad1e7f2183ad31d49122607ef1/server/services/lifecycle/lifecycle.js#L75

This lifecycle uses

https://github.com/meilisearch/strapi-plugin-meilisearch/blob/f322bec2a5cc15ad1e7f2183ad31d49122607ef1/server/services/meilisearch/connector.js#L111 to update the entries in Meilisearch.

To ensure the entry should be present in Meilisearch, the above function uses sanitizeEntries https://github.com/meilisearch/strapi-plugin-meilisearch/blob/f322bec2a5cc15ad1e7f2183ad31d49122607ef1/server/services/meilisearch/connector.js#L119

For some reason, these checks are done one entry at the time and if the entry should not be in Meilisearch, it is deleted. The deletion happens even if the entry was not already present in Meilisearch. This is done to avoid having to first getting the document in Meilisearch and then delete it. Problem is, the entries are deleted one by one. Thus, if you update X documents that are in draft mode for example, they are deleted one by one from Meilisearch. So, X requests are made to Meilisearch.

Now, instead of deleting them one by one, the entries that should be deleted should be deleted in one batch. Instead of doing this: https://github.com/meilisearch/strapi-plugin-meilisearch/blob/f322bec2a5cc15ad1e7f2183ad31d49122607ef1/server/services/meilisearch/connector.js#L126

We should use deleteDocuments.

bidoubiwa avatar Jan 04 '23 12:01 bidoubiwa

DANGER

This endpoint will be deprecated in the near future. Consider using POST /indexes/{index_uid}/documents/delete instead .

In your link, it shows this🤔

qaqland avatar Dec 19 '23 05:12 qaqland