Improve cache invalidation when splitting shared terms.

This changeset addresses two related issues:

* When splitting shared terms from hierarchical taxonomies, the process of regenerating the taxonomy hierarchy (`_get_taxonomy_hierarchy()`) requires recursive calls to `get_terms()` in order to descend the tree. By waiting until all shared terms in a term group have been invalidated before regenerating their taxonomy hierarchies, we avoid certain race conditions.
* Previously, a coding error prevented single-term caches from being invalidated for children of split terms. This error dates from [31418].

See #37189.

git-svn-id: https://develop.svn.wordpress.org/trunk@40920 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Boone Gorges 2017-06-21 04:11:58 +00:00
parent a529129de5
commit 7104971dca

View File

@ -3548,19 +3548,27 @@ function _split_shared_term( $term_id, $term_taxonomy_id, $record = true ) {
array( 'parent' => $new_term_id ),
array( 'term_taxonomy_id' => $child_tt_id )
);
clean_term_cache( $term_id, $term_taxonomy->taxonomy );
clean_term_cache( (int) $child_tt_id, '', false );
}
} else {
// If the term has no children, we must force its taxonomy cache to be rebuilt separately.
clean_term_cache( $new_term_id, $term_taxonomy->taxonomy );
clean_term_cache( $new_term_id, $term_taxonomy->taxonomy, false );
}
clean_term_cache( $term_id, $term_taxonomy->taxonomy, false );
/*
* Taxonomy cache clearing is delayed to avoid race conditions that may occur when
* regenerating the taxonomy's hierarchy tree.
*/
$taxonomies_to_clean = array( $term_taxonomy->taxonomy );
// Clean the cache for term taxonomies formerly shared with the current term.
$shared_term_taxonomies = $wpdb->get_row( $wpdb->prepare( "SELECT taxonomy FROM $wpdb->term_taxonomy WHERE term_id = %d", $term_id ) );
if ( $shared_term_taxonomies ) {
foreach ( $shared_term_taxonomies as $shared_term_taxonomy ) {
clean_term_cache( $term_id, $shared_term_taxonomy );
}
$shared_term_taxonomies = $wpdb->get_col( $wpdb->prepare( "SELECT taxonomy FROM $wpdb->term_taxonomy WHERE term_id = %d", $term_id ) );
$taxonomies_to_clean = array_merge( $taxonomies_to_clean, $shared_term_taxonomies );
foreach ( $taxonomies_to_clean as $taxonomy_to_clean ) {
clean_taxonomy_cache( $taxonomy_to_clean );
}
// Keep a record of term_ids that have been split, keyed by old term_id. See wp_get_split_term().