Increasing Batch Size for Faster Performance ๐Ÿš€

Increasing Batch Size for Faster Performance ๐Ÿš€

Why Increase the Batch Size?

If you have a large number of posts, pages, or custom post types that need indexing, the process can take significant time. Increasing the batch size can help reduce indexing time by processing more documents per batch.

By default, Yuto indexes up to 999 documents per batch because larger batches process faster than smaller ones. For example, indexing 100,000 documents in 2 batches of 50,000 is much quicker than using 4 batches of 25,000. However, Meilisearch limits the maximum payload size to 100MB, which is why the default batch size is set to 999.

Enqueuing the JavaScript File for the Yuto Settings Page

To apply these changes, you need to enqueue the JavaScript file containing the hooks on the Yuto settings page.

How to Increase the Batch Size

Starting from version 0.0.7, you can increase the batch size using the yuto_index_batch_size hook. This hook accepts two parameters:

Parameters:

  • batchSize (Integer) – Defines the batch size. Default: 999
  • UID (String) – The index ID.

Example Usage:

Important Note:

Re-indexing is necessary for the changes made through this hook to take effect.

Increasing Beyond 999: Adjusting the REST API Limit

By default, the WordPress REST API restricts per_page to 100 posts per request. Yuto increases this limit to 999 for all post types. If you want to use a batch size higher than 999, you must first adjust the REST APIโ€™s per_page limit.

Adjusting the REST API per_page Limit

Use the rest_{$post_type}_collection_params filter to increase the maximum per_page value.

Once this change is applied, you can use a batch size greater than 999 within the yuto_index_batch_size hook.

Summary

  • The default batch size is 999, but it can be increased using the yuto_index_batch_size hook.
  • To exceed 999, update the WordPress REST APIโ€™s per_page limit.
  • Ensure that JavaScript hooks are properly enqueued on the Yuto settings page.
  • Ensure to Index the documents again for the changes to take effect.

By following these steps, you can optimize your indexing process for better performance in Yuto. ๐Ÿš€

Leave a Reply

Your email address will not be published. Required fields are marked *