Skip to:
Content

BuddyPress.org

Changeset 9188


Ignore:
Timestamp:
11/26/2014 06:09:42 AM (9 years ago)
Author:
r-a-y
Message:

Messages: Add oEmbed caching.

With the introduction of the messages meta table (#3083), we are now able
to cache oEmbed responses. On subsequent fetches, we will now reference
the message cache instead of pinging the oEmbed provider.

This mirrors our functionality with BP's activity implementation of oEmbed.

See #5990.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-messages/bp-messages-template.php

    r9187 r9188  
    19991999 * Enable oEmbed support for Messages.
    20002000 *
    2001  * There's no caching as BP 1.5 does not have a Messages meta API.
    2002  *
    20032001 * @since BuddyPress (1.5.0)
    20042002 *
    20052003 * @see BP_Embed
    2006  *
    2007  * @todo Add Messages meta?
    20082004 */
    20092005function bp_messages_embed() {
    2010     add_filter( 'embed_post_id', 'bp_get_the_thread_message_id' );
     2006    add_filter( 'embed_post_id',         'bp_get_the_thread_message_id' );
     2007    add_filter( 'bp_embed_get_cache',    'bp_embed_message_cache',      10, 3 );
     2008    add_action( 'bp_embed_update_cache', 'bp_embed_message_save_cache', 10, 3 );
    20112009}
    20122010add_action( 'thread_loop_start', 'bp_messages_embed' );
     2011
     2012/**
     2013 * Fetch a private message item's cached embeds.
     2014 *
     2015 * Used during {@link BP_Embed::parse_oembed()} via {@link bp_messages_embed()}.
     2016 *
     2017 * @since BuddyPress (2.2.0)
     2018 *
     2019 * @param string $cache An empty string passed by BP_Embed::parse_oembed() for
     2020 *        functions like this one to filter.
     2021 * @param int $id The ID of the message item.
     2022 * @param string $cachekey The cache key generated in BP_Embed::parse_oembed().
     2023 * @return mixed The cached embeds for this message item.
     2024 */
     2025function bp_embed_message_cache( $cache, $id, $cachekey ) {
     2026    return bp_messages_get_meta( $id, $cachekey );
     2027}
     2028
     2029/**
     2030 * Set a private message item's embed cache.
     2031 *
     2032 * Used during {@link BP_Embed::parse_oembed()} via {@link bp_messages_embed()}.
     2033 *
     2034 * @since BuddyPress (2.2.0)
     2035 *
     2036 * @param string $cache An empty string passed by BP_Embed::parse_oembed() for
     2037 *        functions like this one to filter.
     2038 * @param string $cachekey The cache key generated in BP_Embed::parse_oembed().
     2039 * @param int $id The ID of the message item.
     2040 * @return bool True on success, false on failure.
     2041 */
     2042function bp_embed_message_save_cache( $cache, $cachekey, $id ) {
     2043    bp_messages_update_meta( $id, $cachekey, $cache );
     2044}
Note: See TracChangeset for help on using the changeset viewer.