Make WordPress Core

Ticket #14759: 14759.diff

File 14759.diff, 2.3 KB (added by markjaquith, 9 years ago)

Attempt at slightly better caching behavior

  • src/wp-admin/includes/ajax-actions.php

    function wp_ajax_imgedit_preview() { 
    180180}
    181181
    182182function wp_ajax_oembed_cache() {
    183         global $wp_embed;
    184 
    185         $return = ( $wp_embed->cache_oembed( $_GET['post'] ) ) ? '1' : '0';
    186         wp_die( $return );
     183        $GLOBALS['wp_embed']->cache_oembed( $_GET['post'] );
     184        wp_die( 0 );
    187185}
    188186
    189187function wp_ajax_autocomplete_user() {
  • src/wp-includes/class-wp-embed.php

    class WP_Embed { 
    2525                // Attempts to embed all URLs in a post
    2626                add_filter( 'the_content', array( $this, 'autoembed' ), 8 );
    2727
    28                 // When a post is saved, invalidate the oEmbed cache
    29                 add_action( 'pre_post_update', array( $this, 'delete_oembed_caches' ) );
    30 
    3128                // After a post is saved, cache oEmbed items via AJAX
    3229                add_action( 'edit_form_advanced', array( $this, 'maybe_run_ajax_cache' ) );
    3330        }
    class WP_Embed { 
    7269        function maybe_run_ajax_cache() {
    7370                $post = get_post();
    7471
    75                 if ( ! $post || empty($_GET['message']) || 1 != $_GET['message'] )
     72                if ( ! $post || empty( $_GET['message'] ) ) {
    7673                        return;
     74                }
    7775
    7876?>
    7977<script type="text/javascript">
    class WP_Embed { 
    183181
    184182                        // Check for a cached result (stored in the post meta)
    185183                        $cachekey = '_oembed_' . md5( $url . serialize( $attr ) );
    186                         if ( $this->usecache ) {
    187                                 $cache = get_post_meta( $post_ID, $cachekey, true );
    188 
     184                        $cache = get_post_meta( $post_ID, $cachekey, true );
     185                        if ( $this->usecache || 'publish' !== get_post_status( $post_ID ) ) {
    189186                                // Failures are cached
    190187                                if ( '{{unknown}}' === $cache )
    191188                                        return $this->maybe_make_link( $url );
    class WP_Embed { 
    219216                        $html = wp_oembed_get( $url, $attr );
    220217
    221218                        // Cache the result
    222                         $cache = ( $html ) ? $html : '{{unknown}}';
    223                         update_post_meta( $post_ID, $cachekey, $cache );
     219                        if ( $html ) {
     220                                update_post_meta( $post_ID, $cachekey, $html );
     221                        } elseif ( ! $cache ) {
     222                                update_post_meta( $post_ID, $cachekey, '{{unknown}}' );
     223                        }
    224224
    225225                        // If there was a result, return it
    226226                        if ( $html ) {