Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Current Orders Cache Query implementation results in more queries than when disabled. #45550

Open
5 tasks done
prettyboymp opened this issue Mar 13, 2024 · 1 comment · May be fixed by #46023
Open
5 tasks done

Current Orders Cache Query implementation results in more queries than when disabled. #45550

prettyboymp opened this issue Mar 13, 2024 · 1 comment · May be fixed by #46023
Labels
focus: data-store Issues related to custom tables. focus: order Issues related to orders. focus: performance The issue/PR is related to performance. priority: normal The issue/PR is of normal priority—not many people are affected or there’s a workaround, etc. team: Proton WC Core development and maintenance type: enhancement The issue is a request for an enhancement.

Comments

@prettyboymp
Copy link
Contributor

Prerequisites

  • I have carried out troubleshooting steps and I believe I have found a bug.
  • I have searched for similar bugs in both open and closed issues and cannot find a duplicate.

Describe the bug

Querying a set of orders with orders_cache_usage_is_enabled() === true results in more queries than when it is disabled when querying a set of orders by ID.

Because the WC_Data::__sleep() method only stores the ID, the WC_Data::__wakeup() method is set to run the initial object constructor again. For orders, this results in two queries being run for each order requested - one for the order data and one for meta.

When caching is disabled, the data for the set of orders and meta can be retrieved for all orders in two queries.

Expected behavior

The expectation behind cached orders is that a successful cache hit of an order would not result in a DB read being made.

Actual behavior

A successful cache hit for an order requires two DB reads because only the ID is stored in cache.

Steps to reproduce

1, Setup an environment with multiple orders and note the IDs.
2. Disabled the orders_cache_usage_is_enabled feature flag.
3. Setup a script to test the number of queries run, e.g.:

$order_ids = [ 1, 2, 3, 4 ];
WC_Order_Factory::get_orders( $order_ids );
$final_query_count = count( $wpdb->queries );
WP_CLI::success( 'Queries run: ' . ( $final_query_count - $initial_query_count ) );
  1. Enable the orders_cache_usage_is_enabled feature flag.
  2. Visit the orders listing admin page to prime cache.
  3. Run the previous script again.

WordPress Environment

WPCOM

Isolating the problem

  • I have deactivated other plugins and confirmed this bug occurs when only WooCommerce plugin is active.
  • This bug happens with a default WordPress theme active, or Storefront.
  • I can reproduce this bug consistently using the steps above.
@prettyboymp
Copy link
Contributor Author

This will likely require reworking the __sleep() / __wakeup() handling within WC_Data. They were originally added because the data objects stored references to more than just raw data, e.g. the datastores which shouldn't be cached.

@jonathansadowski jonathansadowski added focus: data-store Issues related to custom tables. team: Proton WC Core development and maintenance labels Mar 15, 2024
@vedanshujain vedanshujain added priority: high The issue/PR is high priority—it affects lots of customers substantially, but not critically. focus: order Issues related to orders. focus: custom order tables / HPOS type: enhancement The issue is a request for an enhancement. focus: performance The issue/PR is related to performance. labels Mar 21, 2024
@barryhughes barryhughes added priority: normal The issue/PR is of normal priority—not many people are affected or there’s a workaround, etc. and removed priority: high The issue/PR is high priority—it affects lots of customers substantially, but not critically. labels May 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
focus: data-store Issues related to custom tables. focus: order Issues related to orders. focus: performance The issue/PR is related to performance. priority: normal The issue/PR is of normal priority—not many people are affected or there’s a workaround, etc. team: Proton WC Core development and maintenance type: enhancement The issue is a request for an enhancement.
Projects
No open projects
Development

Successfully merging a pull request may close this issue.

5 participants