WordPress.org

Make WordPress Core

#20486 closed defect (bug) (fixed)

Pass full post object to clean_post_cache()

Reported by: duck_ Owned by: duck_
Priority: normal Milestone: 3.4
Component: Cache Version:
Severity: normal Keywords:
Cc:

Description

So that we have the post type without having to get_post() in clean_post_cache() which can cause notices (#19690).

See #20460 for the same for clean_user_cache().

Attachments (3)

20486.diff (5.5 KB) - added by duck_ 14 months ago.
20486.2.diff (5.4 KB) - added by duck_ 14 months ago.
20486.3.diff (5.4 KB) - added by duck_ 14 months ago.

Download all attachments as: .zip

Change History (7)

duck_14 months ago

comment:1 duck_14 months ago

get_post() in clean_post_cache() isn't much of a problem. We just need to check the the result. If it's empty() then we can assume the post isn't cached.

The recommendation/documentation would be to pass an object though.

duck_14 months ago

comment:2 follow-up: GaryJ14 months ago

The second patch still contains a few calls that pass a variable called $post_id through instead of $post. Is that correct? (or can the variables be renamed to be better self-documenting)

duck_14 months ago

comment:3 in reply to: ↑ 2 duck_14 months ago

Replying to GaryJ:

The second patch still contains a few calls that pass a variable called $post_id through instead of $post. Is that correct? (or can the variables be renamed to be better self-documenting)

Yes. I updated the clean_post_cache() to reflect that it can be int or object. This ticket should be "accept an object in clean_post_cache()" and not "unconditionally switch to passing objects". The only situation that the object is actually necessary is when the cache clean is called after a database delete query when we want the object for its post type so we can ensure that the $taxonomy_relationship cache is cleaned.

comment:4 duck_14 months ago

  • Owner set to duck_
  • Resolution set to fixed
  • Status changed from new to closed

In [20569]:

Accept a post object in clean_post_cache(). Fixes #20486.

The post_type can then be accessed to properly clean the taxonomy relationships cache.
The full object is useful in situations when an ID might reference a post that has been
removed from the database (e.g. wp_delete_post()).

Note: See TracTickets for help on using tickets.