Skip to:
Content

bbPress.org


Ignore:
Timestamp:
03/19/2012 05:25:49 PM (12 years ago)
Author:
johnjamesjacoby
Message:

Add caching to topic subscription queries. Props MZAWeb. Fixes #1794.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/plugin/bbp-includes/bbp-user-functions.php

    r3758 r3809  
    530530 */
    531531function bbp_get_topic_subscribers( $topic_id = 0 ) {
    532     if ( empty( $topic_id ) )
    533         return;
     532    if ( empty( $topic_id ) ) return;
    534533
    535534    global $wpdb;
    536535
    537     // Get the users who have favorited the topic
    538     $users = $wpdb->get_col( "SELECT user_id FROM {$wpdb->usermeta} WHERE meta_key = '_bbp_subscriptions' and FIND_IN_SET('{$topic_id}', meta_value) > 0" );
    539     $users = apply_filters( 'bbp_get_topic_subscribers', $users );
    540 
    541     if ( !empty( $users ) )
     536    $users = wp_cache_get( 'bbp_get_topic_subscribers_' . $topic_id, 'bbpress' );
     537    if ( empty( $users ) ) {
     538        $users = $wpdb->get_col( "SELECT user_id FROM {$wpdb->usermeta} WHERE meta_key = '_bbp_subscriptions' and FIND_IN_SET('{$topic_id}', meta_value) > 0" );
     539        wp_cache_set( 'bbp_get_topic_subscribers_' . $topic_id, $users, 'bbpress' );
     540    }
     541
     542    if ( !empty( $users ) ) {
     543        $users = apply_filters( 'bbp_get_topic_subscribers', $users );
    542544        return $users;
     545    }
    543546
    544547    return false;
     
    676679        $subscriptions   = (string) implode( ',', $subscriptions );
    677680        update_user_meta( $user_id, '_bbp_subscriptions', $subscriptions );
     681
     682        wp_cache_delete( 'bbp_get_topic_subscribers_' . $topic_id, 'bbpress' );
    678683    }
    679684
     
    718723            delete_user_meta( $user_id, '_bbp_subscriptions' );
    719724        }
     725
     726        wp_cache_delete( 'bbp_get_topic_subscribers_' . $topic_id, 'bbpress' );
    720727    }
    721728
Note: See TracChangeset for help on using the changeset viewer.