Make WordPress Core

Ticket #40434: 40434-optimize-sql-admin-post-list.diff

File 40434-optimize-sql-admin-post-list.diff, 6.3 KB (added by lriaudel, 8 years ago)

patch Optimization - SQL - Admin - Post list

  • wp-includes/class-wp-query.php

    diff --git wp-includes/class-wp-query.php wp-includes/class-wp-query.php
    index baefec7..e6f5899 100644
    class WP_Query { 
    690690         *                                                 passed. To use 'meta_value', or 'meta_value_num',
    691691         *                                                 'meta_key=keyname' must be also be defined. To sort by a
    692692         *                                                 specific `$meta_query` clause, use that clause's array key.
    693          *                                                 Accepts 'none', 'name', 'author', 'date', 'title',
    694          *                                                 'modified', 'menu_order', 'parent', 'ID', 'rand',
    695          *                                                 'relevance', 'RAND(x)' (where 'x' is an integer seed value),
     693         *                                                 Default 'date'. Accepts 'none', 'name', 'author', 'date',
     694         *                                                 'title', 'modified', 'menu_order', 'parent', 'ID', 'rand',
     695         *                                                 'RAND(x)' (where 'x' is an integer seed value),
    696696         *                                                 'comment_count', 'meta_value', 'meta_value_num', 'post__in',
    697697         *                                                 'post_name__in', 'post_parent__in', and the array keys
    698          *                                                 of `$meta_query`. Default is 'date', except when a search
    699          *                                                 is being performed, when the default is 'relevance'.
    700          *
     698         *                                                 of `$meta_query`.
    701699         *     @type int          $p                       Post ID.
    702700         *     @type int          $page                    Show the number of posts that would show up on page X of a
    703701         *                                                 static front page.
    class WP_Query { 
    17131711                $page = 1;
    17141712
    17151713                if ( isset( $q['caller_get_posts'] ) ) {
    1716                         _deprecated_argument( 'WP_Query', '3.1.0',
    1717                                 /* translators: 1: caller_get_posts, 2: ignore_sticky_posts */
    1718                                 sprintf( __( '%1$s is deprecated. Use %2$s instead.' ),
    1719                                         '<code>caller_get_posts</code>',
    1720                                         '<code>ignore_sticky_posts</code>'
    1721                                 )
    1722                         );
    1723 
    1724                         if ( ! isset( $q['ignore_sticky_posts'] ) ) {
     1714                        _deprecated_argument( 'WP_Query', '3.1.0', __( '"caller_get_posts" is deprecated. Use "ignore_sticky_posts" instead.' ) );
     1715                        if ( !isset( $q['ignore_sticky_posts'] ) )
    17251716                                $q['ignore_sticky_posts'] = $q['caller_get_posts'];
    1726                         }
    17271717                }
    17281718
    17291719                if ( !isset( $q['ignore_sticky_posts'] ) )
    class WP_Query { 
    22972287                $user_id = get_current_user_id();
    22982288
    22992289                $q_status = array();
     2290
    23002291                if ( ! empty( $q['post_status'] ) ) {
     2292
    23012293                        $statuswheres = array();
    23022294                        $q_status = $q['post_status'];
    23032295                        if ( ! is_array( $q_status ) )
    class WP_Query { 
    23562348                                $where .= " AND ($where_status)";
    23572349                        }
    23582350                } elseif ( !$this->is_singular ) {
    2359                         $where .= " AND ({$wpdb->posts}.post_status = 'publish'";
     2351
     2352                        $where_status[] = 'publish';
    23602353
    23612354                        // Add public states.
    23622355                        $public_states = get_post_stati( array('public' => true) );
    23632356                        foreach ( (array) $public_states as $state ) {
    23642357                                if ( 'publish' == $state ) // Publish is hard-coded above.
    23652358                                        continue;
    2366                                 $where .= " OR {$wpdb->posts}.post_status = '$state'";
     2359                                $where_status[] = $state;
    23672360                        }
    23682361
    23692362                        if ( $this->is_admin ) {
    23702363                                // Add protected states that should show in the admin all list.
    23712364                                $admin_all_states = get_post_stati( array('protected' => true, 'show_in_admin_all_list' => true) );
    23722365                                foreach ( (array) $admin_all_states as $state ) {
    2373                                         $where .= " OR {$wpdb->posts}.post_status = '$state'";
     2366                                        $where_status[] = $state;
    23742367                                }
    23752368                        }
    23762369
    class WP_Query { 
    23782371                                // Add private states that are limited to viewing by the author of a post or someone who has caps to read private states.
    23792372                                $private_states = get_post_stati( array('private' => true) );
    23802373                                foreach ( (array) $private_states as $state ) {
    2381                                         $where .= current_user_can( $read_private_cap ) ? " OR {$wpdb->posts}.post_status = '$state'" : " OR {$wpdb->posts}.post_author = $user_id AND {$wpdb->posts}.post_status = '$state'";
     2374                                        $where_status[] = $state;
     2375                                        $where_post_author = current_user_can( $read_private_cap ) ? "" : " OR {$wpdb->posts}.post_author = $user_id";
    23822376                                }
    23832377                        }
    2384 
     2378                        $where .= " AND ( {$wpdb->posts}.post_status IN ('" . implode("','",$where_status) . "')";
     2379                        $where .= $where_post_author;
    23852380                        $where .= ')';
    23862381                }
    23872382
    class WP_Query { 
    23902385                 * manipulations to them are reflected in the paging by day queries.
    23912386                 */
    23922387                if ( !$q['suppress_filters'] ) {
     2388
    23932389                        /**
    23942390                         * Filters the WHERE clause of the query.
    23952391                         *
    class WP_Query { 
    24102406                         */
    24112407                        $join = apply_filters_ref_array( 'posts_join', array( $join, &$this ) );
    24122408                }
    2413 
     2409                       
    24142410                // Paging
    24152411                if ( empty($q['nopaging']) && !$this->is_singular ) {
    24162412                        $page = absint($q['paged']);
    class WP_Query { 
    25192515                 * manipulate paging queries should use these hooks.
    25202516                 */
    25212517                if ( !$q['suppress_filters'] ) {
     2518
    25222519                        /**
    25232520                         * Filters the WHERE clause of the query.
    25242521                         *
    class WP_Query { 
    26312628                 * Regular plugins should use the hooks above.
    26322629                 */
    26332630                if ( !$q['suppress_filters'] ) {
     2631
    26342632                        /**
    26352633                         * Filters the WHERE clause of the query.
    26362634                         *
    class WP_Query { 
    27512749                $this->request = $old_request = "SELECT $found_rows $distinct $fields FROM {$wpdb->posts} $join WHERE 1=1 $where $groupby $orderby $limits";
    27522750
    27532751                if ( !$q['suppress_filters'] ) {
     2752
    27542753                        /**
    27552754                         * Filters the completed SQL query before sending.
    27562755                         *
    class WP_Query { 
    32393238         * @since 1.5.0
    32403239         * @access public
    32413240         *
    3242          * @param string|array $query URL query string or array of query arguments.
     3241         * @param string $query URL query string.
    32433242         * @return array List of posts.
    32443243         */
    32453244        public function query( $query ) {
    class WP_Query { 
    38723871        }
    38733872
    38743873        /**
    3875          * Is the query for an existing single post of any post type (post, attachment, page,
    3876          * custom post types)?
     3874         * Is the query for an existing single post of any post type (post, attachment, page, ... )?
    38773875         *
    38783876         * If the $post_types parameter is specified, this function will additionally
    38793877         * check if the query is for one of the Posts Types specified.