Commit 31fc38239dc for woocommerce
commit 31fc38239dca0350b0eb0a333bbd2ab8552613d5
Author: Alba Rincón <albarin@users.noreply.github.com>
Date: Tue Mar 24 13:40:46 2026 +0100
Add cache priming to AJAX downloadable search, scheduled sales, and recent reviews widget (#63773)
* Add cache priming to AJAX downloadable search, scheduled sales, and recent reviews widget
* Add changefile(s) from automation for the following project(s): woocommerce
* Fix lint
---------
Co-authored-by: woocommercebot <woocommercebot@users.noreply.github.com>
diff --git a/plugins/woocommerce/changelog/63773-add-cache-priming-misc b/plugins/woocommerce/changelog/63773-add-cache-priming-misc
new file mode 100644
index 00000000000..90a14a7285f
--- /dev/null
+++ b/plugins/woocommerce/changelog/63773-add-cache-priming-misc
@@ -0,0 +1,4 @@
+Significance: patch
+Type: performance
+
+Add missing `_prime_post_caches()` calls in AJAX downloadable product search, scheduled sales processing, and Recent Reviews widget to batch-load post data and reduce individual database queries.
\ No newline at end of file
diff --git a/plugins/woocommerce/includes/class-wc-ajax.php b/plugins/woocommerce/includes/class-wc-ajax.php
index 3845f9ab33c..b68876d8782 100644
--- a/plugins/woocommerce/includes/class-wc-ajax.php
+++ b/plugins/woocommerce/includes/class-wc-ajax.php
@@ -1867,6 +1867,7 @@ class WC_AJAX {
$data_store = WC_Data_Store::load( 'product' );
$ids = $data_store->search_products( $term, 'downloadable', true, false, $limit );
+ _prime_post_caches( $ids );
$product_objects = array_filter( array_map( 'wc_get_product', $ids ), 'wc_products_array_filter_readable' );
$products = array();
diff --git a/plugins/woocommerce/includes/wc-product-functions.php b/plugins/woocommerce/includes/wc-product-functions.php
index 06a370b49ac..d215f39957f 100644
--- a/plugins/woocommerce/includes/wc-product-functions.php
+++ b/plugins/woocommerce/includes/wc-product-functions.php
@@ -796,6 +796,7 @@ function wc_scheduled_sales() {
// Sales which are due to start.
$product_ids = $data_store->get_starting_sales();
if ( $product_ids ) {
+ _prime_post_caches( $product_ids );
$must_refresh_transient = true;
do_action( 'wc_before_products_starting_sales', $product_ids );
@@ -817,6 +818,7 @@ function wc_scheduled_sales() {
// Sales which are due to end.
$product_ids = $data_store->get_ending_sales();
if ( $product_ids ) {
+ _prime_post_caches( $product_ids );
$must_refresh_transient = true;
do_action( 'wc_before_products_ending_sales', $product_ids );
diff --git a/plugins/woocommerce/includes/widgets/class-wc-widget-recent-reviews.php b/plugins/woocommerce/includes/widgets/class-wc-widget-recent-reviews.php
index 635e26975b6..eb32a5da77e 100644
--- a/plugins/woocommerce/includes/widgets/class-wc-widget-recent-reviews.php
+++ b/plugins/woocommerce/includes/widgets/class-wc-widget-recent-reviews.php
@@ -59,11 +59,12 @@ class WC_Widget_Recent_Reviews extends WC_Widget {
$number = ! empty( $instance['number'] ) ? absint( $instance['number'] ) : $this->settings['number']['std'];
$comments = get_comments(
array(
- 'number' => $number,
- 'status' => 'approve',
- 'post_status' => 'publish',
- 'post_type' => 'product',
- 'parent' => 0,
+ 'number' => $number,
+ 'status' => 'approve',
+ 'post_status' => 'publish',
+ 'post_type' => 'product',
+ 'parent' => 0,
+ 'update_comment_post_cache' => true,
)
); // WPCS: override ok.