meilisearch / strapi-plugin-meilisearch

A strapi plugin to add your collections to Meilisearch
https://meilisearch.com
MIT License
221 stars 58 forks source link

Add a debounce/throttle on document addition #399

Open bidoubiwa opened 2 years ago

bidoubiwa commented 2 years ago

Description Strapi has not a lot of ways to add documents in batches. Most ways to achieve entry addition is one by one. While it is not a problem with a small number of document addition, if a user add's thousands of document at the time the web-server starts to reject new webserver calls, or abort new additions to its own database.

Error: aborted
262: aborted
Knex: Timeout acquiring a connection. The pool is probably full. Are you missing a .transacting(trx) call?

Another issue is that Meilisearch does not like at all to have small batches. Meilisearch is more performant with one addition of 100Mo of document than it is with 10000 additions of 1 document.

To avoid this, we should create a debounce system or a throttle system that avoid an overload of calls to meilisearch.

Ra0R commented 1 week ago

We are having the same problem with our system. We sync around ~15k documents every day. Adding them to the index one-by-one takes a long time.

Here are the changes I would suggest:

Since Strapi v4.9.0, the createMany()-Lifecycle hook properly returns a count and a set of ids after creation: e.g.

 { count: 2 , ids: [1,2]}

This should be properly handled in this part of the code: https://github.com/meilisearch/strapi-plugin-meilisearch/blob/f47f50a86ee189ec36d1fc8b2a7a1140a847abba/server/services/lifecycle/lifecycle.js#L45C1-L49C11

Either check for Strapi Version or update package.json with "peerDependency": { "Strapi": "^4.9.0"}

Let me know if I can implement this.

brunoocasali commented 4 days ago

That would be nice @Ra0R a PR would be very appreciated!