Opened 7 years ago
Last modified 2 months ago
#46058 new defect (bug)
Extra database calls when use get_the_excerpt() and posts have images
| Reported by: | kg69design | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | Awaiting Review |
| Component: | General | Version: | 5.0.3 |
| Severity: | major | Keywords: | needs-patch |
| Cc: | Focuses: |
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 ); }
Change History (2)
#2
@
2 months ago
Hi. I have attempted to reproduce this issue by following your steps exactly, but I was unable to replicate the extra database calls on WordPress 6.9 using the Twenty Nineteen classic theme.
Could you provide a bit more information?
- Current WordPress Version: Are you still able to reproduce this issue on the latest version of WordPress (6.9)?
- Theme: Which specific theme were you using when you originally encountered this?
- Environment Setup: Are you using any persistent object caching (e.g., Redis or Memcached) in your test environment?
- Plugins: Was this on a completely fresh install with zero active plugins, or were there any utility/developer plugins active?
Note:
See TracTickets
for help on using tickets.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
@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.