Make WordPress Core


Ignore:
Timestamp:
10/19/2009 09:28:44 PM (15 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

File:
1 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]);
Note: See TracChangeset for help on using the changeset viewer.