Make WordPress Core

Changeset 40920


Ignore:
Timestamp:
06/21/2017 04:11:58 AM (9 years ago)
Author:
boonebgorges
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/taxonomy.php

    r40919 r40920  
    35493549                                array( 'term_taxonomy_id' => $child_tt_id )
    35503550                        );
    3551                         clean_term_cache( $term_id, $term_taxonomy->taxonomy );
     3551                        clean_term_cache( (int) $child_tt_id, '', false );
    35523552                }
    35533553        } else {
    35543554                // If the term has no children, we must force its taxonomy cache to be rebuilt separately.
    3555                 clean_term_cache( $new_term_id, $term_taxonomy->taxonomy );
    3556         }
     3555                clean_term_cache( $new_term_id, $term_taxonomy->taxonomy, false );
     3556        }
     3557
     3558        clean_term_cache( $term_id, $term_taxonomy->taxonomy, false );
     3559
     3560        /*
     3561         * Taxonomy cache clearing is delayed to avoid race conditions that may occur when
     3562         * regenerating the taxonomy's hierarchy tree.
     3563         */
     3564        $taxonomies_to_clean = array( $term_taxonomy->taxonomy );
    35573565
    35583566        // Clean the cache for term taxonomies formerly shared with the current term.
    3559         $shared_term_taxonomies = $wpdb->get_row( $wpdb->prepare( "SELECT taxonomy FROM $wpdb->term_taxonomy WHERE term_id = %d", $term_id ) );
    3560         if ( $shared_term_taxonomies ) {
    3561                 foreach ( $shared_term_taxonomies as $shared_term_taxonomy ) {
    3562                         clean_term_cache( $term_id, $shared_term_taxonomy );
    3563                 }
     3567        $shared_term_taxonomies = $wpdb->get_col( $wpdb->prepare( "SELECT taxonomy FROM $wpdb->term_taxonomy WHERE term_id = %d", $term_id ) );
     3568        $taxonomies_to_clean = array_merge( $taxonomies_to_clean, $shared_term_taxonomies );
     3569
     3570        foreach ( $taxonomies_to_clean as $taxonomy_to_clean ) {
     3571                clean_taxonomy_cache( $taxonomy_to_clean );
    35643572        }
    35653573
Note: See TracChangeset for help on using the changeset viewer.