Changeset 27101
- Timestamp:
- 02/06/2014 01:40:05 AM (11 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/taxonomy.php
r27057 r27101 1877 1877 $wpdb->update( $wpdb->term_taxonomy, compact( 'parent' ), array( 'parent' => $term_obj->term_id) + compact( 'taxonomy' ) ); 1878 1878 do_action( 'edited_term_taxonomies', $edit_tt_ids ); 1879 set_taxonomy_last_changed( $taxonomy ); 1879 1880 } 1880 1881 … … 1911 1912 1912 1913 clean_term_cache($term, $taxonomy); 1914 set_taxonomy_last_changed( $taxonomy ); 1913 1915 1914 1916 do_action( 'delete_term', $term, $tt_id, $taxonomy, $deleted_term ); … … 2163 2165 $wpdb->update($wpdb->terms, compact('term_group'), array('term_id' => $alias->term_id) ); 2164 2166 do_action( 'edited_terms', $alias->term_id, $taxonomy ); 2167 set_taxonomy_last_changed( $taxonomy ); 2165 2168 } 2166 2169 } … … 2224 2227 2225 2228 clean_term_cache($term_id, $taxonomy); 2229 set_taxonomy_last_changed( $taxonomy ); 2226 2230 2227 2231 do_action("created_term", $term_id, $tt_id, $taxonomy); … … 2330 2334 2331 2335 wp_cache_delete( $object_id, $taxonomy . '_relationships' ); 2336 set_taxonomy_last_changed( $taxonomy ); 2332 2337 2333 2338 do_action('set_object_terms', $object_id, $terms, $tt_ids, $taxonomy, $append, $old_tt_ids); … … 2408 2413 do_action( 'deleted_term_relationships', $object_id, $tt_ids ); 2409 2414 wp_update_term_count( $tt_ids, $taxonomy ); 2415 set_taxonomy_last_changed( $taxonomy ); 2410 2416 2411 2417 return (bool) $deleted; … … 2566 2572 $wpdb->update( $wpdb->terms, compact('term_group'), array( 'term_id' => $alias->term_id ) ); 2567 2573 do_action( 'edited_terms', $alias->term_id, $taxonomy ); 2574 set_taxonomy_last_changed( $taxonomy ); 2568 2575 } 2569 2576 } … … 2601 2608 2602 2609 clean_term_cache($term_id, $taxonomy); 2610 set_taxonomy_last_changed( $taxonomy ); 2603 2611 2604 2612 do_action("edited_term", $term_id, $tt_id, $taxonomy); … … 2739 2747 $taxonomies = get_object_taxonomies( $object_type ); 2740 2748 2741 foreach ( $object_ids as $id ) 2742 foreach ( $taxonomies as $taxonomy ) 2749 foreach ( $object_ids as $id ) { 2750 foreach ( $taxonomies as $taxonomy ) { 2743 2751 wp_cache_delete($id, "{$taxonomy}_relationships"); 2752 set_taxonomy_last_changed( $taxonomy ); 2753 } 2754 } 2744 2755 2745 2756 do_action('clean_object_term_cache', $object_ids, $object_type); … … 2801 2812 2802 2813 do_action('clean_term_cache', $ids, $taxonomy); 2814 set_taxonomy_last_changed( $taxonomy ); 2803 2815 } 2804 2816 … … 2820 2832 */ 2821 2833 function get_object_term_cache($id, $taxonomy) { 2834 if ( ! post_taxonomy_is_fresh( $id, $taxonomy ) ) { 2835 return false; 2836 } 2822 2837 $cache = wp_cache_get($id, "{$taxonomy}_relationships"); 2823 2838 return $cache; … … 3118 3133 do_action( 'edited_term_taxonomy', $term, $taxonomy ); 3119 3134 } 3135 set_taxonomy_last_changed( $taxonomy->name ); 3120 3136 } 3121 3137 … … 3143 3159 do_action( 'edited_term_taxonomy', $term, $taxonomy ); 3144 3160 } 3161 set_taxonomy_last_changed( $taxonomy->name ); 3145 3162 } 3146 3163 … … 3470 3487 return $parent; 3471 3488 } 3489 3490 /** 3491 * Retrieve the 'last_changed' value for the passed taxonomy. Retrieves 3492 * from cache, if present 3493 * 3494 * @since 3.9.0 3495 * 3496 * @param string $taxonomy 3497 * @return int 3498 */ 3499 function get_taxonomy_last_changed( $taxonomy ) { 3500 $last_changed = wp_cache_get( 'last_changed', $taxonomy ); 3501 if ( ! $last_changed ) { 3502 $last_changed = microtime(); 3503 wp_cache_set( 'last_changed', $last_changed, $taxonomy ); 3504 } 3505 return $last_changed; 3506 } 3507 3508 /** 3509 * Reset 'last_changed' for the passed taxonomy 3510 * 3511 * @since 3.9.0 3512 * 3513 * @param string $taxonomy 3514 * @return int 3515 */ 3516 function set_taxonomy_last_changed( $taxonomy ) { 3517 wp_cache_delete( 'last_changed', $taxonomy ); 3518 return get_taxonomy_last_changed( $taxonomy ); 3519 } 3520 3521 /** 3522 * Determine if a post's cache for the passed taxonomy 3523 * is in sync. 3524 * @since 3.9.0 3525 * 3526 * @param int $id 3527 * @param string $taxonomy 3528 * @return boolean 3529 */ 3530 function post_taxonomy_is_fresh( $id, $taxonomy ) { 3531 $last_changed = get_taxonomy_last_changed( $taxonomy ); 3532 $post_last_changed = wp_cache_get( $id, $taxonomy . '_last_changed' ); 3533 if ( ! $post_last_changed || $last_changed !== $post_last_changed ) { 3534 wp_cache_set( $id, $last_changed, $taxonomy . '_last_changed' ); 3535 return false; 3536 } 3537 return true; 3538 } -
trunk/tests/phpunit/tests/term.php
r27099 r27101 572 572 * @ticket 22526 573 573 */ 574 function test_get_taxonomy_last_changed() { 575 $last_changed = get_taxonomy_last_changed( 'category' ); 576 $last_changed_cache = wp_cache_get( 'last_changed', 'category' ); 577 $this->assertEquals( $last_changed, $last_changed_cache ); 578 wp_cache_delete( 'last_changed', 'category' ); 579 $this->assertEquals( $last_changed, $last_changed_cache ); 580 $last_changed = get_taxonomy_last_changed( 'category' ); 581 $this->assertNotEquals( $last_changed, $last_changed_cache ); 582 583 $last_changed2 = get_taxonomy_last_changed( 'category' ); 584 $this->factory->category->create(); 585 $last_changed3 = get_taxonomy_last_changed( 'category' ); 586 $this->assertNotEquals( $last_changed2, $last_changed3 ); 587 } 588 589 /** 590 * @ticket 22526 591 */ 592 function test_set_taxonomy_last_changed() { 593 $last_changed1 = set_taxonomy_last_changed( 'category' ); 594 $last_changed2 = set_taxonomy_last_changed( 'category' ); 595 $this->assertNotEquals( $last_changed1, $last_changed2 ); 596 597 $last_changed3 = set_taxonomy_last_changed( 'category' ); 598 $last_changed4 = get_taxonomy_last_changed( 'category' ); 599 $this->assertEquals( $last_changed3, $last_changed4 ); 600 } 601 602 /** 603 * @ticket 22526 604 */ 605 function test_post_taxonomy_is_fresh() { 606 $post_id = $this->factory->post->create(); 607 $term_id = $this->factory->category->create( array( 'name' => 'Foo' ) ); 608 wp_set_post_categories( $post_id, $term_id ); 609 610 $this->assertFalse( post_taxonomy_is_fresh( $post_id, 'category' ) ); 611 $this->assertTrue( post_taxonomy_is_fresh( $post_id, 'category' ) ); 612 $this->assertTrue( post_taxonomy_is_fresh( $post_id, 'category' ) ); 613 614 wp_update_term( $term_id, 'category', array( 'name' => 'Bar' ) ); 615 616 $this->assertFalse( post_taxonomy_is_fresh( $post_id, 'category' ) ); 617 get_the_category( $post_id ); 618 $this->assertTrue( post_taxonomy_is_fresh( $post_id, 'category' ) ); 619 } 620 621 /** 622 * @ticket 22526 623 */ 574 624 function test_category_name_change() { 575 625 $term = $this->factory->category->create_and_get( array( 'name' => 'Foo' ) );
Note: See TracChangeset
for help on using the changeset viewer.