0

I am new to customizing WordPress and plugins core functions so I have a questions.

Query monitor says I have a duplicate query that is executed like 13-14 times. The query in question is:

SELECT umeta_id as meta_id, meta_key, meta_value
FROM Am1_usermeta
WHERE user_id = 2
ORDER BY umeta_id

It comes from WooCommerce and the callers are:

WC_Data_Store_WP->read_meta()
wp-content/plugins/woocommerce/includes/data-stores/class-wc-data-store-wp.php:94
WC_Data_Store->__call()
wp-content/plugins/woocommerce/includes/class-wc-data-store.php:224
WC_Data->read_meta_data()
wp-content/plugins/woocommerce/includes/abstracts/abstract-wc-data.php:633
WC_Customer_Data_Store->read()
wp-content/plugins/woocommerce/includes/data-stores/class-wc-customer-data-store.php:179
WC_Data_Store->read()
wp-content/plugins/woocommerce/includes/class-wc-data-store.php:159
WC_Customer->__construct()
wp-content/plugins/woocommerce/includes/class-wc-customer.php:113
WooCommerce->initialize_cart()
wp-content/plugins/woocommerce/includes/class-woocommerce.php:847
wc_load_cart()
wp-content/plugins/woocommerce/includes/wc-core-functions.php:2574
WooCommerce->init()
wp-content/plugins/woocommerce/includes/class-woocommerce.php:666
do_action('init')
wp-includes/plugin.php:517

I have Redis cache enabled and I guess this should not happen but still.

My question is is it possible to store this query in cache or transient or cache it using my themes functions php?

Also is it possible, and how, to completely rewrite a query?

I've made a few searches but couldn't find detailed description if and how this is possible.

My goal is to make some optimization to reduce the page load times.

1 Answer 1

0

You could certainly write a wrapper function that implements caching of the WooCommerce core functionality, but WooCommerce isn't going to use your wrapper function, so pretty pointless.

Your best option is to create and use your own data store for WooCommerce that extends the WC_Data_Store_WP class, and add caching to those functions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.