WordPress.org

Make WordPress Core

Opened 5 years ago

Closed 5 years ago

#29911 closed defect (bug) (fixed)

Deleting a term does not invalidate cache for child terms

Reported by: boonebgorges Owned by: boonebgorges
Milestone: 4.1 Priority: normal
Severity: normal Version:
Component: Taxonomy Keywords: needs-patch good-first-bug
Focuses: Cc:
PR Number:

Description

See #29614.

Steps to reproduce:

  1. Create a $term in a hierarchical taxonomy
  2. Create a $child_term with parent=$term
  3. wp_delete_term( $term )
  4. Fetch cached version of $child_term with get_term(). 'parent' is still $term.

Unit test attached.

Two options to fix:

  1. During deletion, run a query to get term_ids of all child terms, then run each through clean_term_cache().
  2. During deletion, instead of doing a direct DB query to change the parent, run each item through wp_update_term().

Option 2 is much more aesthetically pleasing, but in cases where a parent has hundreds of children, there could be scaling issues, as separate DB queries would be run for each. Could use some testing, and a patch.

Attachments (2)

29911.test.patch (985 bytes) - added by boonebgorges 5 years ago.
29911.patch (426 bytes) - added by socki03 5 years ago.
Added clean term cache for the term's children.

Download all attachments as: .zip

Change History (7)

#1 @nacin
5 years ago

Option 1 is what we do for posts. See wp_delete_post(). Very simple and straightforward.

This ticket was mentioned in IRC in #wordpress-dev by DrewAPicture. View the logs.


5 years ago

@socki03
5 years ago

Added clean term cache for the term's children.

#3 @socki03
5 years ago

I was able to replicate the issue, and my initial tests resolved it with this patch resolved it.

I noticed from the documentation, that clean_term_cache can accept an array of IDs, so I ran it once using the $edit_tt_ids variable instead of a foreach loop, as is done on the clean_post_cache.

#4 @boonebgorges
5 years ago

  • Milestone changed from Future Release to 4.1

Thanks for the patch. You're right about clean_term_cache(). However, the ids passed to that function are expected to be term_id, not term_taxonomy_id.

#5 @boonebgorges
5 years ago

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

In 29945:

Invalidate cache for child terms when parent term is deleted.

Props socki03.
Fixes #29911.

Note: See TracTickets for help on using tickets.