Make WordPress Core


Ignore:
Timestamp:
08/12/2011 01:55:08 AM (13 years ago)
Author:
markjaquith
Message:

Eliminate verbose rewrite rules for ambiguous rewrite structures, resulting in massive performance gains. props andy, otto42, duck_. Nice work everyone! see #16687

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/rewrite.php

    r18540 r18541  
    307307    $request_match = $request;
    308308    foreach ( (array)$rewrite as $match => $query) {
     309
    309310        // If the requesting file is the anchor of the match, prepend it
    310311        // to the path info.
     
    313314
    314315        if ( preg_match("!^$match!", $request_match, $matches) ) {
     316
     317            if ( $wp_rewrite->use_verbose_page_rules && preg_match( '/pagename=\$([^&\[]+)\[([0-9]+)\]/', $query, $varmatch ) ) {
     318                // this is a verbose page match, lets check to be sure about it
     319                if ( ! get_page_by_path( ${$varmatch[1]}[$varmatch[2]] ) )
     320                    continue;
     321            }
     322
    315323            // Got a match.
    316324            // Trim the query of everything up to the '?'.
     
    814822        $page_structure = $this->get_page_permastruct();
    815823
    816         if ( ! $this->use_verbose_page_rules ) {
    817             $this->add_rewrite_tag('%pagename%', "(.+?)", 'pagename=');
    818             $rewrite_rules = array_merge($rewrite_rules, $this->generate_rewrite_rules($page_structure, EP_PAGES));
    819             return $rewrite_rules;
    820         }
    821 
    822         $page_uris = $this->page_uri_index();
    823         $uris = $page_uris[0];
    824         $attachment_uris = $page_uris[1];
    825 
    826         if ( is_array( $attachment_uris ) ) {
    827             foreach ( $attachment_uris as $uri => $pagename ) {
    828                 $this->add_rewrite_tag('%pagename%', "($uri)", 'attachment=');
    829                 $rewrite_rules = array_merge($rewrite_rules, $this->generate_rewrite_rules($page_structure, EP_PAGES));
    830             }
    831         }
    832         if ( is_array( $uris ) ) {
    833             foreach ( $uris as $uri => $pagename ) {
    834                 $this->add_rewrite_tag('%pagename%', "($uri)", 'pagename=');
    835                 $rewrite_rules = array_merge($rewrite_rules, $this->generate_rewrite_rules($page_structure, EP_PAGES));
    836             }
    837         }
    838 
     824        // the extra .? at the beginning prevents clashes with other regex's in thie structure
     825        $this->add_rewrite_tag('%pagename%', "(.?.+?)", 'pagename=');
     826        $rewrite_rules = array_merge($rewrite_rules, $this->generate_rewrite_rules($page_structure, EP_PAGES));
    839827        return $rewrite_rules;
    840828    }
     
    15541542        // Put them together.
    15551543        if ( $this->use_verbose_page_rules )
    1556             $this->rules = array_merge($this->extra_rules_top, $robots_rewrite, $old_feed_files, $registration_pages, $page_rewrite, $root_rewrite, $comments_rewrite, $search_rewrite,  $author_rewrite, $date_rewrite, $post_rewrite, $this->extra_rules);
     1544            $this->rules = array_merge($this->extra_rules_top, $robots_rewrite, $old_feed_files, $registration_pages, $root_rewrite, $comments_rewrite, $search_rewrite,  $author_rewrite, $date_rewrite, $page_rewrite, $post_rewrite, $this->extra_rules);
    15571545        else
    15581546            $this->rules = array_merge($this->extra_rules_top, $robots_rewrite, $old_feed_files, $registration_pages, $root_rewrite, $comments_rewrite, $search_rewrite,  $author_rewrite, $date_rewrite, $post_rewrite, $page_rewrite, $this->extra_rules);
Note: See TracChangeset for help on using the changeset viewer.