Make WordPress Core

Ticket #40613: 40613.patch

File 40613.patch, 3.1 KB (added by johnjamesjacoby, 8 years ago)
  • src/wp-includes/class-wp-user-query.php

    diff --git src/wp-includes/class-wp-user-query.php src/wp-includes/class-wp-user-query.php
    index 4522f7e..4083d04 100644
     
    596596
    597597                $this->request = "SELECT $this->query_fields $this->query_from $this->query_where $this->query_orderby $this->query_limit";
    598598
    599                 if ( is_array( $qv['fields'] ) || 'all' == $qv['fields'] ) {
    600                         $this->results = $wpdb->get_results( $this->request );
    601                 } else {
    602                         $this->results = $wpdb->get_col( $this->request );
    603                 }
     599                // Get
     600                $cache_key    = md5( serialize( wp_array_slice_assoc( $this->query_vars, array_keys( $this->fill_query_vars( array() ) ) ) ) );
     601                $last_changed = wp_cache_get_last_changed( 'users' );
     602                $cache_key    = "get_users:{$cache_key}:{$last_changed}";
     603                $cache_value  = wp_cache_get( $cache_key, 'users' );
    604604
    605                 /**
    606                  * Filters SELECT FOUND_ROWS() query for the current WP_User_Query instance.
    607                  *
    608                  * @since 3.2.0
    609                  *
    610                  * @global wpdb $wpdb WordPress database abstraction object.
    611                  *
    612                  * @param string $sql The SELECT FOUND_ROWS() query for the current WP_User_Query.
    613                  */
    614                 if ( isset( $qv['count_total'] ) && $qv['count_total'] )
    615                         $this->total_users = (int) $wpdb->get_var( apply_filters( 'found_users_query', 'SELECT FOUND_ROWS()' ) );
     605                if ( false === $cache_value ) {
     606                        if ( is_array( $qv['fields'] ) || 'all' == $qv['fields'] ) {
     607                                $this->results = $wpdb->get_results( $this->request );
     608                        } else {
     609                                $this->results = $wpdb->get_col( $this->request );
     610                        }
     611
     612                        /**
     613                         * Filters SELECT FOUND_ROWS() query for the current WP_User_Query instance.
     614                         *
     615                         * @since 3.2.0
     616                         *
     617                         * @global wpdb $wpdb WordPress database abstraction object.
     618                         *
     619                         * @param string $sql The SELECT FOUND_ROWS() query for the current WP_User_Query.
     620                         */
     621                        if ( isset( $qv['count_total'] ) && $qv['count_total'] ) {
     622                                $this->total_users = (int) $wpdb->get_var( apply_filters( 'found_users_query', 'SELECT FOUND_ROWS()' ) );
     623                        }
     624
     625                        // Setup array to cache
     626                        $cache_value = array(
     627                                'users'       => $this->results,
     628                                'found_users' => (int) $this->total_users,
     629                        );
     630
     631                        // Add results to cache to cache
     632                        wp_cache_add( $cache_key, $cache_value, 'users' );
     633                } else {
     634                        $this->results     = $cache_value['users'];
     635                        $this->total_users = (int) $cache_value['found_users'];
     636                }
    616637
    617638                if ( !$this->results )
    618639                        return;
  • src/wp-includes/user.php

    diff --git src/wp-includes/user.php src/wp-includes/user.php
    index 2bb4e05..9402182 100644
     
    12901290        wp_cache_delete( $user->user_login, 'userlogins' );
    12911291        wp_cache_delete( $user->user_email, 'useremail' );
    12921292        wp_cache_delete( $user->user_nicename, 'userslugs' );
     1293        wp_cache_delete( 'last_changed', 'users' );
    12931294
    12941295        /**
    12951296         * Fires immediately after the given user's cache is cleaned.
     
    16931694        } elseif ( ! $update ) {
    16941695                $user->set_role(get_option('default_role'));
    16951696        }
    1696         wp_cache_delete( $user_id, 'users' );
    1697         wp_cache_delete( $user_login, 'userlogins' );
     1697
     1698        clean_user_cache( $user );
    16981699
    16991700        if ( $update ) {
    17001701                /**