Make WordPress Core

Opened 6 weeks ago

Last modified 6 weeks ago

#65587 new enhancement

wp-embed performs extra query even when unnecessary

Reported by: gddrt Owned by:
Priority: normal Milestone: Awaiting Review
Component: Embeds Version: trunk
Severity: trivial Keywords: has-patch
Cc: Focuses: performance

Description (last modified by gddrt)

Cached oembed data can be stored in two ways: as post meta, or as a standalone post of type oembed_cache (when the embed does not belong to a post for some reason.)

In class-wp-embed, it checks for cached embed data by first querying the oembed_cache post. Then it checks for post meta associated with the defined post_id (which is read from the global $post.) If there is a post_id, the result of the oembed_cache post query is ignored.

<?php
$cached_post_id = $this->find_oembed_post_id( $key_suffix );

if ( $post_id ) {
        $cache      = get_post_meta( $post_id, $cachekey, true );
        $cache_time = get_post_meta( $post_id, $cachekey_time, true );

        if ( ! $cache_time ) {
                $cache_time = 0;
        }
} elseif ( $cached_post_id ) {
        $cached_post = get_post( $cached_post_id );

        $cache      = $cached_post->post_content;
        $cache_time = strtotime( $cached_post->post_modified_gmt );
}

find_oembed_post_id should only be called if post_id is not set.

Change History (4)

This ticket was mentioned in PR #12427 on WordPress/wordpress-develop by @gddrt.


6 weeks ago
#1

  • Keywords has-patch added

Do not perform unnecessary oembed_cache post query when the cached oembed has already been found in post meta

Trac ticket: #65587

This ticket was mentioned in PR #12428 on WordPress/wordpress-develop by @gddrt.


6 weeks ago
#2

Do not perform unnecessary oembed_cache post query when the cached oembed has already been found in post meta

Trac ticket: #65587

@gddrt commented on PR #12427:


6 weeks ago
#3

Sorry -- got the commit history fouled up, will create a new PR.

#4 @gddrt
6 weeks ago

  • Description modified (diff)

Correction: The oembed_cache post is only checked if post_id (which is read from the global $post) is not set. If post_id is set, the oembed_cache query result is ignored, whether or not a cached embed result exists in post meta.

Note: See TracTickets for help on using tickets.