Opened 6 years ago
Last modified 4 years ago
#46058 new defect (bug)
Extra database calls when use get_the_excerpt() and posts have images
Reported by: | kg69design | Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | major | Version: | 5.0.3 |
Component: | General | Keywords: | needs-patch |
Focuses: | Cc: |
Description
To reproduce this issue:
- Install clear wordpress (5.0.3)
- Create post with image in post content. Assign it to one category (e.g. "uncategorized").
- Open this category page and check database calls in it (with get_num_queries()).
- Add one more post with image in it - and database calls will increase with every additional post (+2 queries for 1 additional post).
Info:
- This issue dissapear when you delete get_the_excerpt() from the category template.
- This issue does not exist when posts have no image in it.
The reason of this issue is in function get_the_excerpt():
- function get_the_excerpt() applies filter 'get_the_excerpt' in wp-includes/post-template.php:397
<?php return apply_filters( 'get_the_excerpt', $post->post_excerpt, $post );
- we have 'wp_trim_excerpt' by default for 'get_the_excerpt' in "wp-includes/default-filters.php:172":
<?php add_filter( 'get_the_excerpt', 'wp_trim_excerpt' );
- function wp_trim_excerpt() applies filter 'the_content' in wp-includes/formatting.php:3314
<?php $text = apply_filters( 'the_content', $text );
- we have 'wp_make_content_images_responsive' by default for 'the_content' in "wp-includes/default-filters.php:165":
<?php add_filter( 'the_content', 'wp_make_content_images_responsive' );
- 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 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 ); }
Note: See
TracTickets for help on using
tickets.
@kg69design I'm going to take a look into this soon but not today. I just made a note to see if I can replicate and then I will come up with a plan of action after that if I can replicate it.