ElasticPress icon indicating copy to clipboard operation
ElasticPress copied to clipboard

Compatibility with WooCommerce HPOS

Open felipeelia opened this issue 1 year ago • 5 comments

Is your enhancement related to a problem? Please describe.

This issue is to investigate ElasticPress's compatibility with WooCommerce High-Performance Order Storage.

My findings so far:

  • 100% compatibility would be very hard to achieve, as data requests to the new custom table are spread throughout the code base, like here, for example;
  • It seems the best candidate for a replacement with a compatibility layer would be the OrdersTableQuery class, as it is responsible for running queries
  • The OrdersTableQuery class is called directly by the OrdersTableDataStore class here, so we might need to override that one too.
  • Due to the way the WC container works, it won't allow us to simply replace a class, so we might need a new filter to be added.

Code of Conduct

  • [X] I agree to follow this project's Code of Conduct

felipeelia avatar May 31 '23 14:05 felipeelia

Hey @felipeelia , from WC team here. I would love to help you with HPOS compatibility for ElasticPress. It looks like currently you hook into posts_pre_query to hijack WP query and populate results from elasticsearch, would be happy to add similar filter for HPOS as well. It seems we won't need to create new index for HPOS orders, since there is already a allowlist for what data can be synced, and we can add HPOS orders in the same index (note that we always insert a shop_order_placehold post and use the same ID in order tables, so a ID conflict won't happen).

Let us know if there is anything else you would need besides an equivalent posts_pre_query filter.

vedanshujain avatar Aug 21 '23 14:08 vedanshujain

@vedanshujain you got it right. It is worth saying though that an equivalent filter for posts_pre_query would be a good start, but we will probably need some further changes, especially given the number of times the code seems to be touching the database directly.

felipeelia avatar Aug 24 '23 17:08 felipeelia

Cool cool, we will get a PR started for posts_pre_query. Please let us know what you discover during development, we would be happy to add more action/filters where they makes sense, and especially if a similar filter already exists with the posts.

vedanshujain avatar Aug 25 '23 05:08 vedanshujain

@felipeelia , I can try and give it a shot for a draft PR, if this is still on the roadmap?

vedanshujain avatar Apr 01 '24 09:04 vedanshujain

To have this one done, in general steps, we need to:

  1. Create a new file called OrdersHPOS.php in includes/classes/Feature/WooCommerce/
  2. Conditionally call it from includes/classes/Feature/WooCommerce/Orders.php
  3. Make Orders be indexed in ElasticPress posts' index
  4. Use the woocommerce_hpos_pre_query filter to prevent any SQL query from being fired and use ElasticPress instead.

felipeelia avatar Jul 11 '24 13:07 felipeelia