Make WordPress Core

Ticket #18840: get_pages_inexclusions_sql_optimisation.patch

File get_pages_inexclusions_sql_optimisation.patch, 1.3 KB (added by 5ubliminal, 14 years ago)
  • post.php

     
    33793379                $hierarchical = false;
    33803380                $incpages = wp_parse_id_list( $include );
    33813381                if ( ! empty( $incpages ) ) {
    3382                         foreach ( $incpages as $incpage ) {
    3383                                 if (empty($inclusions))
    3384                                         $inclusions = $wpdb->prepare(' AND ( ID = %d ', $incpage);
    3385                                 else
    3386                                         $inclusions .= $wpdb->prepare(' OR ID = %d ', $incpage);
    3387                         }
     3382                        // We have ints here as wp_parse_id_list() made sure of that.
     3383                        // So we just combine them in a subset and avoid the extra ->prepare().
     3384                        // And we also shorten the query ALOT ;) (alots rule)
     3385                        $inclusions = ' AND ID IN ('.implode(', ', $incpages).')';
    33883386                }
    33893387        }
    3390         if (!empty($inclusions))
    3391                 $inclusions .= ')';
    33923388
    33933389        $exclusions = '';
    33943390        if ( !empty($exclude) ) {
    33953391                $expages = wp_parse_id_list( $exclude );
    33963392                if ( ! empty( $expages ) ) {
    3397                         foreach ( $expages as $expage ) {
    3398                                 if (empty($exclusions))
    3399                                         $exclusions = $wpdb->prepare(' AND ( ID <> %d ', $expage);
    3400                                 else
    3401                                         $exclusions .= $wpdb->prepare(' AND ID <> %d ', $expage);
    3402                         }
     3393                        // Same optimization as with $inclusions
     3394                        $exclusions = ' AND ID NOT IN ('.implode(', ', $expages).')';
    34033395                }
    34043396        }
    3405         if (!empty($exclusions))
    3406                 $exclusions .= ')';
    34073397
    34083398        $author_query = '';
    34093399        if (!empty($authors)) {