Make WordPress Core

Opened 8 months ago

Closed 8 months ago

Last modified 5 months ago

#63850 closed defect (bug) (fixed)

Avoid doing an extra call to cache/wpdb when post_id is not valid

Reported by: bor0's profile bor0 Owned by: sergeybiryukov's profile SergeyBiryukov
Milestone: 6.9 Priority: normal
Severity: normal Version:
Component: Posts, Post Types Keywords: has-patch
Focuses: Cc:

Description

While investigating an issue on WooCommerce.com, we discovered that some plugins invoke WP_Post::get_instance( -1 ).

Although one could argue this is a plugin-level problem, we noticed that WordPress still processes the request and unnecessarily performs calls to wp_cache_get and wpdb->get_row.

We propose adding a short-circuit to handle cases where post_id is negative, not just when it equals zero.

Attachments (1)

63850.patch (360 bytes) - added by bor0 8 months ago.

Download all attachments as: .zip

Change History (6)

@bor0
8 months ago

#1 @bor0
8 months ago

Props @akeda for the patch.

@SergeyBiryukov could use your input here as well. Thanks a ton 🙏

#2 @SergeyBiryukov
8 months ago

  • Component changed from General to Posts, Post Types
  • Keywords has-patch added
  • Milestone changed from Awaiting Review to 6.9
  • Owner set to SergeyBiryukov
  • Status changed from new to accepted

#3 @SergeyBiryukov
8 months ago

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

In 60654:

Posts, Post Types: Avoid an extra database query in WP_Post for a negative post ID.

Follow-up to [21559].

Props bor0, akeda, SergeyBiryukov.
Fixes #63850.

#4 @bor0
8 months ago

@SergeyBiryukov, I really admire your prompt actions.

I owe you a ton of beer and/or coffee, whichever your drink preference is.

Thank you!

#5 @Howdy_McGee
5 months ago

Created a new enhancement ticket for supporting Faux WP_Post Objects #64362

Last edited 5 months ago by Howdy_McGee (previous) (diff)
Note: See TracTickets for help on using tickets.