From 8ca91024e8bc4e7c13519bcd68d6825450653d22 Mon Sep 17 00:00:00 2001 From: Boone Gorges Date: Wed, 21 Jun 2017 04:12:44 +0000 Subject: [PATCH] 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. Built from https://develop.svn.wordpress.org/trunk@40920 git-svn-id: http://core.svn.wordpress.org/trunk@40770 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/taxonomy.php | 22 +++++++++++++++------- wp-includes/version.php | 2 +- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/wp-includes/taxonomy.php b/wp-includes/taxonomy.php index 484d26ebbc..f703b5a56b 100644 --- a/wp-includes/taxonomy.php +++ b/wp-includes/taxonomy.php @@ -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(). diff --git a/wp-includes/version.php b/wp-includes/version.php index 53969d5b73..c3f8190348 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.9-alpha-40919'; +$wp_version = '4.9-alpha-40920'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.