Commit 6ca7de0bec2 for woocommerce

commit 6ca7de0bec2afa4e4aabfe87476099c08feecde7
Author: Alba Rincón <albarin@users.noreply.github.com>
Date:   Tue Apr 21 10:14:00 2026 +0200

    Prime attachment caches in product gallery meta box to reduce edit screen queries (#64089)

    * Prime attachment caches in product gallery meta box to reduce edit screen queries

    * Add changefile(s) from automation for the following project(s): woocommerce

    ---------

    Co-authored-by: woocommercebot <woocommercebot@users.noreply.github.com>

diff --git a/plugins/woocommerce/changelog/64089-fix-prime-product-images-metabox b/plugins/woocommerce/changelog/64089-fix-prime-product-images-metabox
new file mode 100644
index 00000000000..48f1b80ca9d
--- /dev/null
+++ b/plugins/woocommerce/changelog/64089-fix-prime-product-images-metabox
@@ -0,0 +1,4 @@
+Significance: patch
+Type: performance
+
+Reduce the number of database queries on the product edit screen by priming attachment caches before rendering the product gallery meta box.
\ No newline at end of file
diff --git a/plugins/woocommerce/includes/admin/meta-boxes/class-wc-meta-box-product-images.php b/plugins/woocommerce/includes/admin/meta-boxes/class-wc-meta-box-product-images.php
index db6c419624a..867d1b4d03c 100644
--- a/plugins/woocommerce/includes/admin/meta-boxes/class-wc-meta-box-product-images.php
+++ b/plugins/woocommerce/includes/admin/meta-boxes/class-wc-meta-box-product-images.php
@@ -43,6 +43,9 @@ class WC_Meta_Box_Product_Images {
 				$updated_gallery_ids = array();

 				if ( ! empty( $attachments ) ) {
+					// Prime caches to reduce future queries.
+					_prime_post_caches( $attachments );
+
 					foreach ( $attachments as $attachment_id ) {
 						$attachment = wp_get_attachment_image( $attachment_id, 'thumbnail' );