Make WordPress Core

Opened 6 years ago

Last modified 15 months ago

#44772 new enhancement

Optimize `get_the_post_thumbnail_url` call

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


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 6 years ago.

Download all attachments as: .zip

Change History (6)

#1 @birgire
6 years ago

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

6 years ago

#2 @soulseekah
6 years ago

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

#3 @mukesh27
6 years ago

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

#4 @SergeyBiryukov
6 years 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.

#5 @flixos90
15 months ago

+1 to what @SergeyBiryukov says. I would expect any performance impact here to be negligible, and the benefit of calling get_post() helps ensure that the provided post ID is actually valid.

I would therefore advise to close this ticket.

Note: See TracTickets for help on using tickets.