Changeset 27102
- Timestamp:
- 02/06/2014 01:58:01 AM (11 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/taxonomy.php
r27101 r27102 2949 2949 if ( !is_taxonomy_hierarchical($taxonomy) ) 2950 2950 return array(); 2951 $children = get_option("{$taxonomy}_children"); 2951 $children = false; 2952 if ( taxonomy_hierarchy_is_fresh( $taxonomy ) ) { 2953 $children = get_option("{$taxonomy}_children"); 2954 } 2952 2955 2953 2956 if ( is_array($children) ) … … 3522 3525 * Determine if a post's cache for the passed taxonomy 3523 3526 * is in sync. 3527 * 3524 3528 * @since 3.9.0 3525 3529 * … … 3537 3541 return true; 3538 3542 } 3543 3544 /** 3545 * Determine if a hierarchy's cache for the passed taxonomy 3546 * is in sync. 3547 * 3548 * @since 3.9.0 3549 * 3550 * @param int $id 3551 * @param string $taxonomy 3552 * @return boolean 3553 */ 3554 function taxonomy_hierarchy_is_fresh( $taxonomy ) { 3555 $last_changed = get_taxonomy_last_changed( $taxonomy ); 3556 $hierarchy_last_changed = wp_cache_get( 'hierarchy_last_changed', $taxonomy ); 3557 if ( ! $hierarchy_last_changed || $last_changed !== $hierarchy_last_changed ) { 3558 wp_cache_set( 'hierarchy_last_changed', $last_changed, $taxonomy ); 3559 return false; 3560 } 3561 return true; 3562 } -
trunk/tests/phpunit/tests/term.php
r27101 r27102 586 586 $this->assertNotEquals( $last_changed2, $last_changed3 ); 587 587 } 588 588 589 589 /** 590 590 * @ticket 22526 … … 635 635 $this->assertNotEquals( $term->name, reset( $cats2 )->name ); 636 636 } 637 638 function test_hierachy_invalidation() { 639 $tax = 'burrito'; 640 register_taxonomy( $tax, 'post', array( 'hierarchical' => true ) ); 641 $this->assertTrue( get_taxonomy( $tax )->hierarchical ); 642 643 $step = 1; 644 $parent_id = 0; 645 $children = 0; 646 647 foreach ( range( 1, 99 ) as $i ) { 648 switch ( $step ) { 649 case 1: 650 $parent = wp_insert_term( 'Parent' . $i, $tax ); 651 $parent_id = $parent['term_id']; 652 break; 653 case 2: 654 $parent = wp_insert_term( 'Child' . $i, $tax, array( 'parent' => $parent_id ) ); 655 $parent_id = $parent['term_id']; 656 $children++; 657 break; 658 case 3: 659 wp_insert_term( 'Grandchild' . $i, $tax, array( 'parent' => $parent_id ) ); 660 $parent_id = 0; 661 $children++; 662 break; 663 } 664 665 $terms = get_terms( $tax, array( 'hide_empty' => false ) ); 666 $this->assertEquals( $i, count( $terms ) ); 667 if ( 1 < $i ) { 668 $hierarchy = _get_term_hierarchy( $tax ); 669 $this->assertNotEmpty( $hierarchy ); 670 $this->assertEquals( $children, count( $hierarchy, COUNT_RECURSIVE ) - count( $hierarchy ) ); 671 } 672 673 if ( $i % 3 === 0 ) { 674 $step = 1; 675 } else { 676 $step++; 677 } 678 } 679 680 _unregister_taxonomy( $tax ); 681 } 637 682 }
Note: See TracChangeset
for help on using the changeset viewer.