Ticket #42252: 42252.3.diff
File 42252.3.diff, 6.2 KB (added by , 3 years ago) |
---|
-
src/wp-includes/class-wp-query.php
968 968 } 969 969 } 970 970 971 971 972 if ( !empty($qv['post_type']) ) { 972 973 if ( is_array($qv['post_type']) ) 973 974 $qv['post_type'] = array_map('sanitize_key', $qv['post_type']); … … 2257 2258 $where .= " AND {$wpdb->posts}.post_type = 'post'"; 2258 2259 $post_type_object = get_post_type_object ( 'post' ); 2259 2260 } 2260 2261 2261 $edit_cap = 'edit_post'; 2262 2262 $read_cap = 'read_post'; 2263 2263 -
src/wp-includes/class-wp-site-query.php
240 240 */ 241 241 do_action_ref_array( 'pre_get_sites', array( &$this ) ); 242 242 243 // $args can include anything. Only use the args defined in the query_var_defaults to compute the key. 244 $_args = wp_array_slice_assoc( $this->query_vars, array_keys( $this->query_var_defaults ) ); 245 246 // Ignore the $fields argument as the queried result will be the same regardless. 247 unset( $_args['fields'] ); 243 $cache_key = $this->get_cache_key( $this->query_vars ); 248 244 249 $key = md5( serialize( $_args ) );250 $last_changed = wp_cache_get_last_changed( 'sites' );251 252 $cache_key = "get_sites:$key:$last_changed";253 245 $cache_value = wp_cache_get( $cache_key, 'sites' ); 254 246 255 247 if ( false === $cache_value ) { … … 698 690 return 'DESC'; 699 691 } 700 692 } 693 694 /** 695 * Generates the cache key to lookup query results for a specific set of arguments. 696 * 697 * @since 5.0.0 698 * 699 * @param array $query_vars Array of WP_Site_Query arguments. See WP_Site_Query::__construct(). 700 * @return string Cache key to use for the lookup. 701 */ 702 protected function get_cache_key( $query_vars ) { 703 // $args can include anything. Only use the args defined in the query_var_defaults to compute the key. 704 $_args = wp_array_slice_assoc( $query_vars, array_keys( $this->query_var_defaults ) ); 705 706 // Ignore the $fields argument as the queried result will be the same regardless. 707 unset( $_args['fields'] ); 708 709 // Ignore the $update_site_cache as it does not affect the query. 710 unset( $_args['update_site_cache'] ); 711 712 // Use the same cache key for array lookups with one element and single value lookups. 713 $single_multi_mappings = array( 714 'ID' => 'site__in', 715 'network_id' => 'network__in', 716 'domain' => 'domain__in', 717 'path' => 'path__in', 718 'lang_id' => 'lang__in', 719 ); 720 foreach ( $single_multi_mappings as $single_var => $multi_var ) { 721 if ( empty( $_args[ $single_var ] ) && isset( $_args[ $multi_var ] ) && is_array( $_args[ $multi_var ] ) && count( $_args[ $multi_var ] ) === 1 ) { 722 $_args[ $single_var ] = array_pop( $_args[ $multi_var ] ); 723 $_args[ $multi_var ] = ''; 724 } 725 } 726 727 $key = md5( serialize( $_args ) ); 728 $used_args = array_filter( $_args ); 729 $params = array( 'domain', 'path', 'network_id' ); 730 $array_keys = array_intersect( $params, array_keys( $used_args ) ); 731 $last_changed_prefix = array(); 732 $counter = count( $array_keys ); 733 if ( $counter > 0 ) { 734 foreach ( $params as $param ) { 735 if ( ! isset( $used_args[ $param ] ) || empty( $used_args[ $param ] ) ) { 736 if ( $counter > 1 ) { 737 break; 738 } 739 continue; 740 } 741 $last_changed_prefix[$param] = $used_args[ $param ]; 742 } 743 } 744 $last_changed_key = 'last_changed'; 745 if ( $last_changed_prefix ) { 746 $last_changed_prefix = md5( serialize( $last_changed_prefix ) ); 747 $last_changed_key = $last_changed_prefix . '_last_changed'; 748 } 749 $last_changed = wp_cache_get_last_changed( 'sites', $last_changed_key ); 750 751 return "get_sites:$key:$last_changed"; 752 } 701 753 } -
src/wp-includes/functions.php
5710 5710 * Get last changed date for the specified cache group. 5711 5711 * 5712 5712 * @since 4.7.0 5713 * @since 5.0.0 Now supports the $prefix parameter. 5713 5714 * 5714 * @param string $group Where the cache contents are grouped. 5715 * @param string $group Where the cache contents are grouped. 5716 * @param string $key Optional. Key to look for a specific last changed key. Default empty string. 5715 5717 * 5716 5718 * @return string $last_changed UNIX timestamp with microseconds representing when the group was last changed. 5717 5719 */ 5718 function wp_cache_get_last_changed( $group ) { 5719 $last_changed = wp_cache_get( 'last_changed', $group ); 5720 function wp_cache_get_last_changed( $group, $key = '' ) { 5721 if ( empty( $key ) ) { 5722 $key = 'last_changed'; 5723 } 5724 $last_changed = wp_cache_get( $key, $group ); 5720 5725 5721 5726 if ( ! $last_changed ) { 5722 5727 $last_changed = microtime(); 5723 wp_cache_set( 'last_changed', $last_changed, $group );5728 wp_cache_set( $key, $last_changed, $group ); 5724 5729 } 5725 5730 5726 5731 return $last_changed; -
src/wp-includes/ms-blogs.php
447 447 'blog_id' => $blog_id, 448 448 'domain' => null, 449 449 'path' => null, 450 'site_id' => get_current_network_id(), 450 451 ) ); 451 452 } 452 453 … … 473 474 */ 474 475 do_action( 'clean_site_cache', $blog_id, $blog, $domain_path_key ); 475 476 476 wp_cache_set( 'last_changed', microtime(), 'sites' ); 477 $current_time = microtime(); 478 479 $last_changed_keys = array( 'last_changed' ); 480 $params = array( 'domain', 'path', 'site_id' ); 481 $last_changed_prefix = array(); 482 foreach ( $params as $param ) { 483 $last_changed_keys[] = md5( serialize( array( $param => $blog->$param ) ) ) . '_last_changed'; 484 $last_changed_prefix[ $param ] = $blog->$param; 485 $key = md5( serialize( $last_changed_prefix ) ); 486 $last_changed_keys[] = $key . '_last_changed'; 487 } 488 489 $last_changed_keys = array_unique( $last_changed_keys ); 490 foreach ( $last_changed_keys as $last_changed_key ) { 491 wp_cache_set( $last_changed_key, $current_time, 'sites' ); 492 } 477 493 478 494 /** 479 495 * Fires after the blog details cache is cleared.