Commit da39036c39 for woocommerce

commit da39036c397da8c54d53b23b212a1f1f0904b7a8
Author: Vladimir Reznichenko <kalessil@gmail.com>
Date:   Wed Jan 28 12:38:24 2026 +0100

    [Performance] Products: prime caches before constructing product object (#62998)

diff --git a/plugins/woocommerce/changelog/performance-62986-cache-priming-in-product-factory b/plugins/woocommerce/changelog/performance-62986-cache-priming-in-product-factory
new file mode 100644
index 0000000000..2d7af6bfcf
--- /dev/null
+++ b/plugins/woocommerce/changelog/performance-62986-cache-priming-in-product-factory
@@ -0,0 +1,4 @@
+Significance: patch
+Type: performance
+
+Products: reduce the number of SQL queries needed to construct product objects.
diff --git a/plugins/woocommerce/includes/class-wc-product-factory.php b/plugins/woocommerce/includes/class-wc-product-factory.php
index 0e60d91444..b1d6f7fc0d 100644
--- a/plugins/woocommerce/includes/class-wc-product-factory.php
+++ b/plugins/woocommerce/includes/class-wc-product-factory.php
@@ -21,12 +21,12 @@ class WC_Product_Factory {
 	/**
 	 * Get a product.
 	 *
-	 * @param mixed $product_id WC_Product|WP_Post|int|bool $product Product instance, post instance, numeric or false to use global $post.
+	 * @param mixed $product_id Product instance, post instance, numeric or false to use global $post.
 	 * @param array $deprecated Previously used to pass arguments to the factory, e.g. to force a type.
-	 * @return WC_Product|bool Product object or false if the product cannot be loaded.
+	 * @return WC_Product|bool  Product object or false if the product cannot be loaded.
 	 */
 	public function get_product( $product_id = false, $deprecated = array() ) {
-		$product_id = $this->get_product_id( $product_id );
+		$product_id = (int) $this->get_product_id( $product_id );

 		if ( ! $product_id ) {
 			return false;
@@ -36,11 +36,12 @@ class WC_Product_Factory {
 		if ( $use_product_cache && empty( $deprecated ) ) {
 			// Nothing should be using the $deprecated argument still, but avoid using cache if they are.
 			$product_cache = wc_get_container()->get( ProductCache::class );
-			$product       = $product_cache->get( (int) $product_id );
+			$product       = $product_cache->get( $product_id );
 			if ( $product ) {
 				return $product;
 			}
 		}
+		_prime_post_caches( array( $product_id ) );

 		$product_type = self::get_product_type( $product_id );

diff --git a/plugins/woocommerce/phpstan-baseline.neon b/plugins/woocommerce/phpstan-baseline.neon
index 7741e4c300..bd51a4b02d 100644
--- a/plugins/woocommerce/phpstan-baseline.neon
+++ b/plugins/woocommerce/phpstan-baseline.neon
@@ -17580,18 +17580,6 @@ parameters:
 			count: 1
 			path: includes/class-wc-product-factory.php

-		-
-			message: '#^Parameter \#1 \$product_id of static method WC_Product_Factory\:\:get_product_classname\(\) expects int, int\<min, \-1\>\|int\<1, max\>\|true given\.$#'
-			identifier: argument.type
-			count: 1
-			path: includes/class-wc-product-factory.php
-
-		-
-			message: '#^Parameter \#1 \$product_id of static method WC_Product_Factory\:\:get_product_type\(\) expects int, int\<min, \-1\>\|int\<1, max\>\|true given\.$#'
-			identifier: argument.type
-			count: 1
-			path: includes/class-wc-product-factory.php
-
 		-
 			message: '#^Parameter \#2 \$product_type of static method WC_Product_Factory\:\:get_product_classname\(\) expects string, string\|false given\.$#'
 			identifier: argument.type