[wp-trac] [WordPress Trac] #46058: Extra database calls when use get_the_excerpt() and posts have images

WordPress Trac noreply at wordpress.org
Mon Jan 21 23:49:51 UTC 2019


#46058: Extra database calls when use get_the_excerpt() and posts have images
--------------------------+-----------------------------
 Reporter:  kg69design    |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  General       |    Version:  5.0.3
 Severity:  major         |   Keywords:  needs-patch
  Focuses:                |
--------------------------+-----------------------------
 **To reproduce this issue:**
 1. Install clear wordpress (5.0.3)
 2. Create post with image in post content. Assign it to one category (e.g.
 "uncategorized").
 3. Open this category page and check database calls in it (with
 get_num_queries()).
 4. Add one more post with image in it - and database calls will increase
 with every additional post (+2 queries for 1 additional post).


 **Info:**
 1. This issue dissapear when you delete get_the_excerpt() from the
 category template.
 2. This issue does not exist when posts have no image in it.


 **The reason of this issue is in function get_the_excerpt():**
 1. function get_the_excerpt() applies filter 'get_the_excerpt' in wp-
 includes/post-template.php:397
 {{{#!php
 <?php
 return apply_filters( 'get_the_excerpt', $post->post_excerpt, $post );
 }}}

 2. we have 'wp_trim_excerpt' by default for 'get_the_excerpt' in "wp-
 includes/default-filters.php:172":
 {{{#!php
 <?php
 add_filter( 'get_the_excerpt', 'wp_trim_excerpt'  );
 }}}

 3. function wp_trim_excerpt() applies filter 'the_content' in wp-
 includes/formatting.php:3314
 {{{#!php
 <?php
 $text = apply_filters( 'the_content', $text );
 }}}

 4. we have 'wp_make_content_images_responsive' by default for
 'the_content' in "wp-includes/default-filters.php:165":
 {{{#!php
 <?php
 add_filter( 'the_content', 'wp_make_content_images_responsive' );
 }}}

 5. and lastly function wp_make_content_images_responsive() produce 2 extra
 database calls on every post in category-page (guess with
 wp_get_attachment_metadata) in wp-includes/media.php:1344
 {{{#!php
 <?php
 foreach ( $selected_images as $image => $attachment_id ) {
   $image_meta = wp_get_attachment_metadata( $attachment_id );
   $content = str_replace( $image, wp_image_add_srcset_and_sizes( $image,
 $image_meta, $attachment_id ), $content );
 }
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/46058>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list