WordPress.org

Make WordPress Core

Opened 8 years ago

Closed 8 years ago

Last modified 7 years ago

#20486 closed defect (bug) (fixed)

Pass full post object to clean_post_cache()

Reported by: duck_ Owned by: duck_
Milestone: 3.4 Priority: normal
Severity: normal Version:
Component: Cache API Keywords:
Focuses: 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_ 8 years ago.
20486.2.diff (5.4 KB) - added by duck_ 8 years ago.
20486.3.diff (5.4 KB) - added by duck_ 8 years ago.

Download all attachments as: .zip

Change History (8)

@duck_
8 years ago

#1 @duck_
8 years 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_
8 years ago

#2 follow-up: @GaryJ
8 years 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_
8 years ago

#3 in reply to: ↑ 2 @duck_
8 years 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.

#4 @duck_
8 years 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()).

#5 @ocean90
7 years ago

#16182 was marked as a duplicate.

Note: See TracTickets for help on using tickets.