WordPress.org

Make WordPress Core

Changeset 12062


Ignore:
Timestamp:
10/19/09 21:28:44 (6 years ago)
Author:
ryan
Message:

Improve sanitize_post() performance. Perform raw filtering only once. Add filter check to eliminate double filtering. Props johanee. fixes #10972 see #10801

Location:
trunk/wp-includes
Files:
2 edited

Legend:

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

    r12054 r12062  
    233233    } elseif ( is_object($post) && empty($post->filter) ) { 
    234234        _get_post_ancestors($post); 
    235         wp_cache_add($post->ID, $post, 'posts'); 
    236         $_post = &$post; 
     235        $_post = sanitize_post($post, 'raw'); 
     236        wp_cache_add($post->ID, $_post, 'posts'); 
    237237    } else { 
    238238        if ( is_object($post) ) 
     
    244244                return $null; 
    245245            _get_post_ancestors($_post); 
     246            $_post = sanitize_post($_post, 'raw'); 
    246247            wp_cache_add($_post->ID, $_post, 'posts'); 
    247248        } 
    248249    } 
    249250 
    250     $_post = sanitize_post($_post, $filter); 
     251    if ($filter != 'raw') 
     252        $_post = sanitize_post($_post, $filter); 
    251253 
    252254    if ( $output == OBJECT ) { 
     
    818820function sanitize_post($post, $context = 'display') { 
    819821    if ( is_object($post) ) { 
     822        // Check if post already filtered for this context 
     823        if ( isset($post->filter) && $context == $post->filter ) 
     824            return $post; 
    820825        if ( !isset($post->ID) ) 
    821826            $post->ID = 0; 
     
    824829        $post->filter = $context; 
    825830    } else { 
     831        // Check if post already filtered for this context 
     832        if ( isset($post['filter']) && $context == $post['filter'] ) 
     833            return $post; 
    826834        if ( !isset($post['ID']) ) 
    827835            $post['ID'] = 0; 
     
    24512459    } 
    24522460 
     2461    // Sanitize before caching so it'll only get done once 
     2462    $num_pages = count($pages); 
     2463    for ($i = 0; $i < $num_pages; $i++) { 
     2464        $pages[$i] = sanitize_post($pages[$i], 'raw'); 
     2465    } 
     2466 
    24532467    // Update cache. 
    24542468    update_page_cache($pages); 
     
    24662480            $excludes[] = $child->ID; 
    24672481        $excludes[] = $exclude; 
    2468         $total = count($pages); 
    2469         for ( $i = 0; $i < $total; $i++ ) { 
     2482        for ( $i = 0; $i < $num_pages; $i++ ) { 
    24702483            if ( in_array($pages[$i]->ID, $excludes) ) 
    24712484                unset($pages[$i]); 
  • trunk/wp-includes/query.php

    r12052 r12062  
    23612361            $this->posts = apply_filters('the_posts', $this->posts); 
    23622362 
     2363        $this->post_count = count($this->posts); 
     2364 
     2365        // Sanitize before caching so it'll only get done once 
     2366        for ($i = 0; $i < $this->post_count; $i++) { 
     2367            $this->posts[$i] = sanitize_post($this->posts[$i], 'raw'); 
     2368        } 
     2369 
    23632370        update_post_caches($this->posts); 
    23642371 
    2365         $this->post_count = count($this->posts); 
    23662372        if ($this->post_count > 0) { 
    23672373            $this->post = $this->posts[0]; 
Note: See TracChangeset for help on using the changeset viewer.