WordPress.org

Make WordPress Core

Opened 6 weeks ago

Last modified 6 weeks ago

#49446 new enhancement

cache the results of get_uploaded_header_images()

Reported by: pbiron Owned by:
Milestone: 5.5 Priority: normal
Severity: normal Version:
Component: Cache API Keywords:
Focuses: administration, performance Cc:

Description

If the current theme supports custom-header and is_random_header_image() is true, then _media_states() calls get_uploaded_header_images() for every row in the media list table.

If the results of get_uploaded_header_images() were cached, the media list table would render much quicker, especially if the number of media displayed per page is large.

There is already an inline comment @todo Caching which has apparently been there since get_uploaded_header_images() was added in [17757].

Attachments (1)

49446.diff (923 bytes) - added by SergeyBiryukov 6 weeks ago.

Download all attachments as: .zip

Change History (5)

This ticket was mentioned in Slack in #core-media by pbiron. View the logs.


6 weeks ago

@SergeyBiryukov
6 weeks ago

#2 in reply to: ↑ description ; follow-up: @SergeyBiryukov
6 weeks ago

Replying to pbiron:

If the current theme supports custom-header and is_random_header_image() is true, then _media_states() calls get_uploaded_header_images() for every row in the media list table.

Even with caching added, saving $header_images to a static variable in _media_states() seems like a quick win to avoid having to go through wp_list_pluck() for the result of get_uploaded_header_images() for every row.

#3 in reply to: ↑ 2 @pbiron
6 weeks ago

Replying to SergeyBiryukov:

Even with caching added, saving $header_images to a static variable in _media_states() seems like a quick win to avoid having to go through wp_list_pluck() for the result of get_uploaded_header_images() for every row.

Agreed...that's kind how I stumbled on this. I've got a custom plugin that does a relatively complex query hooked to display_media_states and storing the results in a static sped things up considerably.

I went looking for more improvements and was going to suggest exactly the patch you added...then found that inline comment about caching in get_uploaded_header_images() :-)

#4 @SergeyBiryukov
6 weeks ago

  • Milestone changed from Awaiting Review to 5.5
Note: See TracTickets for help on using tickets.