WordPress.org

Make WordPress Core

Opened 16 months ago

Last modified 16 months ago

#44772 new enhancement

Optimize `get_the_post_thumbnail_url` call

Reported by: soulseekah Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Post Thumbnails Keywords: has-patch reporter-feedback
Focuses: performance Cc:
PR Number:

Description

This function merely returns the post meta using the post ID. In cases where an ID is passed there's no need to fetch the complete WP_Post object, use it directly as the post ID in the get_post_meta call.

Attachments (1)

44772.diff (765 bytes) - added by soulseekah 16 months ago.

Download all attachments as: .zip

Change History (5)

#1 @birgire
16 months ago

It looks like some dbdelta changes came through with the patch.

@soulseekah
16 months ago

#2 @soulseekah
16 months ago

@birgire Eek, cached diff changes from another ticket I was working on. Thanks for noticing! Replaced.

#3 @mukesh27
16 months ago

  • Component changed from General to Post Thumbnails
  • Focuses performance added

#4 @SergeyBiryukov
16 months ago

  • Keywords reporter-feedback added

Hi @soulseekah, thanks for the patch! get_post() was introduced in [34167].

Do you have any performance benchmarks for this change? get_post() calls are cached, so I don't expect there to be a huge difference.

The current code has an additional benefit of validating if the post exists before calling get_post_meta(). With the patch, the return value type changes from an empty string to a boolean false. This would need to be reflected in the docs and could be a potential back compat issue if someone only accounts for the (currently documented) string value in their code.

Note: See TracTickets for help on using tickets.