From 2ecd08a60d43776da59a635ca1d51ed0710d35a3 Mon Sep 17 00:00:00 2001 From: Nirav Sherasiya Date: Sun, 9 Jul 2023 11:57:47 +0530 Subject: [PATCH 1/3] Add: function _prime_post_caches to improve the performance by caching _prime_post_caches to to cache the attachments if it's not in cache, by caching the posts will improve the performance the code behaviour remains same. --- src/wp-includes/widgets/class-wp-widget-media-gallery.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/wp-includes/widgets/class-wp-widget-media-gallery.php b/src/wp-includes/widgets/class-wp-widget-media-gallery.php index 40cc5c2ba4664..64df4b3e2f4b9 100644 --- a/src/wp-includes/widgets/class-wp-widget-media-gallery.php +++ b/src/wp-includes/widgets/class-wp-widget-media-gallery.php @@ -248,6 +248,7 @@ public function render_control_template_scripts() { protected function has_content( $instance ) { if ( ! empty( $instance['ids'] ) ) { $attachments = wp_parse_id_list( $instance['ids'] ); + _prime_post_caches( $attachments ); foreach ( $attachments as $attachment ) { if ( 'attachment' !== get_post_type( $attachment ) ) { return false; From 91c0a83a94626f9ff4f7ab86452a1e5b4e126876 Mon Sep 17 00:00:00 2001 From: Nirav Sherasiya Date: Thu, 31 Aug 2023 11:20:02 +0530 Subject: [PATCH 2/3] Add: false to update meta and term cache --- src/wp-includes/widgets/class-wp-widget-media-gallery.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wp-includes/widgets/class-wp-widget-media-gallery.php b/src/wp-includes/widgets/class-wp-widget-media-gallery.php index 64df4b3e2f4b9..8c698498f3db9 100644 --- a/src/wp-includes/widgets/class-wp-widget-media-gallery.php +++ b/src/wp-includes/widgets/class-wp-widget-media-gallery.php @@ -248,7 +248,7 @@ public function render_control_template_scripts() { protected function has_content( $instance ) { if ( ! empty( $instance['ids'] ) ) { $attachments = wp_parse_id_list( $instance['ids'] ); - _prime_post_caches( $attachments ); + _prime_post_caches( $attachments, false, false ); foreach ( $attachments as $attachment ) { if ( 'attachment' !== get_post_type( $attachment ) ) { return false; From 43445ab2e5fadd5796bb2d825471f099609a3765 Mon Sep 17 00:00:00 2001 From: Nirav sherasiya <56816580+nirav7707@users.noreply.github.com> Date: Thu, 31 Aug 2023 15:25:34 +0530 Subject: [PATCH 3/3] Apply suggestions from code review Co-authored-by: Mukesh Panchal --- src/wp-includes/widgets/class-wp-widget-media-gallery.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/wp-includes/widgets/class-wp-widget-media-gallery.php b/src/wp-includes/widgets/class-wp-widget-media-gallery.php index 8c698498f3db9..ecc446c2218b0 100644 --- a/src/wp-includes/widgets/class-wp-widget-media-gallery.php +++ b/src/wp-includes/widgets/class-wp-widget-media-gallery.php @@ -248,6 +248,7 @@ public function render_control_template_scripts() { protected function has_content( $instance ) { if ( ! empty( $instance['ids'] ) ) { $attachments = wp_parse_id_list( $instance['ids'] ); + // Prime attachment post caches. _prime_post_caches( $attachments, false, false ); foreach ( $attachments as $attachment ) { if ( 'attachment' !== get_post_type( $attachment ) ) {