Make WordPress Core

Changeset 24091


Ignore:
Timestamp:
04/25/2013 07:10:35 AM (13 years ago)
Author:
markjaquith
Message:

Smarter structured post format caching.

fixes #24002. props kovshenin, wonderboymusic.

File:
1 edited

Legend:

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

    r24083 r24091  
    20642064                return '';
    20652065
    2066         if ( isset( $post->format_content ) )
    2067                 return $post->format_content;
     2066        $cache_key = "media:{$type}";
     2067
     2068        if ( isset( $post->format_content[ $cache_key ] ) )
     2069                return $post->format_content[ $cache_key ];
     2070
     2071        if ( ! isset( $post->format_content ) )
     2072                $post->format_content = array();
    20682073
    20692074        $count = 1;
     
    20792084                                $shortcode = $value;
    20802085                        } elseif ( preg_match( '#<[^>]+>#', $value ) ) {
    2081                                 $post->format_content = $value;
    2082                                 return $post->format_content;
     2086                                $post->format_content[ $cache_key ] = $value;
     2087                                return $post->format_content[ $cache_key ];
    20832088                        } elseif ( 0 === strpos( $value, 'http' ) ) {
    20842089                                $post->split_content = str_replace( $value, '', $post->post_content, $count );
     
    20862091                                        $shortcode = sprintf( '[%s src="%s"]', $type, $value );
    20872092                                } else {
    2088                                         $post->format_content = $wp_embed->autoembed( $value );
    2089                                         return $post->format_content;
     2093                                        $post->format_content[ $cache_key ] = $wp_embed->autoembed( $value );
     2094                                        return $post->format_content[ $cache_key ];
    20902095                                }
    20912096                        }
    20922097
    20932098                        if ( ! empty( $shortcode ) ) {
    2094                                 $post->format_content = do_shortcode( $shortcode );
    2095                                 return $post->format_content;
     2099                                $post->format_content[ $cache_key ] = do_shortcode( $shortcode );
     2100                                return $post->format_content[ $cache_key ];
    20962101                        }
    20972102                }
     
    21052110                $html = reset( $htmls );
    21062111                $post->split_content = $content;
    2107                 $post->format_content = $html;
    2108                 return $post->format_content;
     2112                $post->format_content[ $cache_key ] = $html;
     2113                return $post->format_content[ $cache_key ];
    21092114        }
    21102115
     
    21152120                if ( 0 === strpos( $embed, 'http' ) ) {
    21162121                        if ( strstr( $embed, home_url() ) ) {
    2117                                 $post->format_content = do_shortcode( sprintf( '[%s src="%s"]', $type, $embed ) );
     2122                                $post->format_content[ $cache_key ] = do_shortcode( sprintf( '[%s src="%s"]', $type, $embed ) );
    21182123                        } else {
    2119                                 $post->format_content = $wp_embed->autoembed( $embed );
     2124                                $post->format_content[ $cache_key ] = $wp_embed->autoembed( $embed );
    21202125                        }
    21212126                } else {
    2122                         $post->format_content = $embed;
    2123                 }
    2124                 return $post->format_content;
     2127                        $post->format_content[ $cache_key ] = $embed;
     2128                }
     2129                return $post->format_content[ $cache_key ];
    21252130        }
    21262131
     
    21302135                $url = wp_get_attachment_url( $media->ID );
    21312136                $shortcode = sprintf( '[%s src="%s"]', $type, $url );
    2132                 $post->format_content = do_shortcode( $shortcode );
    2133                 return $post->format_content;
     2137                $post->format_content[ $cache_key ] = do_shortcode( $shortcode );
     2138                return $post->format_content[ $cache_key ];
    21342139        }
    21352140
     
    24092414                return '';
    24102415
    2411         if ( isset( $post->format_content ) && false !== strpos( $post->format_content, 'attachment-' . $attached_size ) )
    2412                 return $post->format_content;
     2416        $cache_key = "image:{$attached_size}";
     2417
     2418        if ( isset( $post->format_content[ $cache_key ] ) )
     2419                return $post->format_content[ $cache_key ];
     2420
     2421        if ( ! isset( $post->format_content ) )
     2422                $post->format_content = array();
    24132423
    24142424        $matched = false;
     
    24442454
    24452455                if ( false === strpos( $image, '<a ' ) )
    2446                         $post->format_content = sprintf( $link_fmt, $image );
     2456                        $post->format_content[ $cache_key ] = sprintf( $link_fmt, $image );
    24472457                else
    2448                         $post->format_content = $image;
    2449                 return $post->format_content;
     2458                        $post->format_content[ $cache_key ] = $image;
     2459                return $post->format_content[ $cache_key ];
    24502460        }
    24512461
     
    25012511                if ( ! $matched ) {
    25022512                        $image = wp_get_attachment_image( $media->ID, $attached_size );
    2503                         $post->format_content = sprintf( $link_fmt, $image );
     2513                        $post->format_content[ $cache_key ] = sprintf( $link_fmt, $image );
    25042514                } else {
    2505                         $post->format_content = $matched;
     2515                        $post->format_content[ $cache_key ] = $matched;
    25062516                        if ( ! empty( $meta['url'] ) && false === stripos( $matched, '<a ' ) )
    2507                                 $post->format_content = sprintf( $link_fmt, $matched );
    2508                 }
    2509                 return $post->format_content;
     2517                                $post->format_content[ $cache_key ] = sprintf( $link_fmt, $matched );
     2518                }
     2519                return $post->format_content[ $cache_key ];
    25102520        }
    25112521
     
    25152525                $html = reset( $htmls );
    25162526                $post->split_content = $content;
    2517                 $post->format_content = sprintf( $link_fmt, $html );
    2518                 return $post->format_content;
     2527                $post->format_content[ $cache_key ] = sprintf( $link_fmt, $html );
     2528                return $post->format_content[ $cache_key ];
    25192529        }
    25202530}
Note: See TracChangeset for help on using the changeset viewer.