Make WordPress Core

Opened 10 months ago

Closed 8 months ago

Last modified 8 months ago

#58757 closed enhancement (fixed)

Performance issue has_content method in WP_Widget_Media_Gallery

Reported by: spacedmonkey's profile spacedmonkey Owned by: niravsherasiya7707's profile niravsherasiya7707
Milestone: 6.4 Priority: normal
Severity: normal Version:
Component: Widgets Keywords: good-first-bug has-patch commit
Focuses: performance Cc:


The has_content method in WP_Widget_Media_Gallery, does not prime post caches before calling get_post_type. Call _prime_post_caches before foreach loop would improve performance.

Change History (10)

This ticket was mentioned in PR #4819 on WordPress/wordpress-develop by nirav7707.

10 months ago

  • Keywords has-patch added

Trac Ticke

  • PR used to add the _prime_post_caches( $attachments ); to cache the posts before iterate to enhance performance.

#2 @spacedmonkey
10 months ago

  • Owner set to niravsherasiya7707
  • Status changed from new to assigned

#3 @niravsherasiya7707
10 months ago

Hello @spacedmonkey, I have a concern regarding the GitHub action "End-to-end Tests / E2E Tests with SCRIPT_DEBUG enabled/disable." I noticed that this action passes successfully on my pull request (PR), which is against my forked branch. However, when I submitted the same PR to the WordPress Trunk, it failed. I would appreciate any insights or guidance you can provide to help resolve this matter.

#4 @swissspidy
10 months ago

@niravsherasiya7707 This is a known issue in trunk right now, nothing to do with your PR. Feel free to ignore.

#5 @oglekler
8 months ago

@spacedmonkey are you satisfied with this patch? How can can proceed? If nesting is the next step, we need an instruction.

#6 @spacedmonkey
8 months ago

  • Keywords changes-requested added

I have some feedback here

Once committed, I will test and commit to core.

#7 @niravsherasiya7707
8 months ago

@spacedmonkey Requested changes are done, please go ahead for next step. Thanks

#8 @mukesh27
8 months ago

  • Keywords commit added; changes-requested removed

Thank you, @niravsherasiya7707, for updating the PR. With sufficient approvals, I am mark it for the final commit.

#9 @spacedmonkey
8 months ago

  • Resolution set to fixed
  • Status changed from assigned to closed

In 56512:

Widgets: Improve performance of has_content method in WP_Widget_Media_Gallery class.

In the method WP_Widget_Media_Gallery::has_content call _prime_post_caches before the foreach loop. This ensures that the post objects are primed in memory before trying to access the post object in get_post_type.

Props niravsherasiya7707, spacedmonkey, mukesh27.
Fixes #58757.

This ticket was mentioned in Slack in #core-performance by spacedmonkey. View the logs.

8 months ago

Note: See TracTickets for help on using tickets.