Skip to:
Content

bbPress.org

Changeset 6218


Ignore:
Timestamp:
01/12/2017 07:07:16 AM (4 years ago)
Author:
johnjamesjacoby
Message:

Users: Remove post__in queries from favs/subs template loops.

This is only recently possible thanks to postmeta storage, and should result in a not-insignificant performance boost for those user profile pages.

See #2959.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/includes/users/functions.php

    r6216 r6218  
    288288 *
    289289 * @param int $user_id Optional. User id
    290  * @uses bbp_get_user_favorites_topic_ids() To get the user's favorites
    291290 * @uses bbp_has_topics() To get the topics
    292291 * @uses apply_filters() Calls 'bbp_get_user_favorites' with the topic query and
     
    295294 */
    296295function bbp_get_user_favorites( $user_id = 0 ) {
    297     $user_id   = bbp_get_user_id( $user_id );
    298     $favorites = bbp_get_user_favorites_topic_ids( $user_id );
    299     $query     = ! empty( $favorites )
    300         ? bbp_has_topics( array( 'post__in' => $favorites ) )
    301         : false;
    302 
    303     return apply_filters( 'bbp_get_user_favorites', $query, $user_id, $favorites );
     296    $user_id = bbp_get_user_id( $user_id );
     297    $query   = bbp_has_topics( array(
     298        'meta_query' => array(
     299            array(
     300                'key'     => '_bbp_favorite',
     301                'value'   => $user_id,
     302                'compare' => 'NUMERIC'
     303            )
     304        )
     305    ) );
     306
     307    return apply_filters( 'bbp_get_user_favorites', $query, $user_id );
    304308}
    305309
     
    612616 *
    613617 * @param int $user_id Optional. User id
    614  * @uses bbp_get_user_subscribed_topic_ids() To get the user's subscriptions
    615618 * @uses bbp_has_topics() To get the topics
    616619 * @uses apply_filters() Calls 'bbp_get_user_subscriptions' with the topic query
     
    619622 */
    620623function bbp_get_user_topic_subscriptions( $user_id = 0 ) {
    621 
    622     // Default to the displayed user
    623     $user_id       = bbp_get_user_id( $user_id );
    624     $subscriptions = bbp_get_user_subscribed_topic_ids( $user_id );
    625 
    626     // If user has subscriptions, load them
    627     if ( ! empty( $subscriptions ) ) {
    628         $query = bbp_has_topics( array( 'post__in' => $subscriptions ) );
    629     } else {
    630         $query = false;
    631     }
     624    $user_id = bbp_get_user_id( $user_id );
     625    $query   = bbp_has_topics( array(
     626        'meta_query' => array(
     627            array(
     628                'key'     => '_bbp_subscription',
     629                'value'   => $user_id,
     630                'compare' => 'NUMERIC'
     631            )
     632        )
     633    ) );
    632634
    633635    return apply_filters( 'bbp_get_user_topic_subscriptions', $query, $user_id );
     
    640642 *
    641643 * @param int $user_id Optional. User id
    642  * @uses bbp_get_user_subscribed_forum_ids() To get the user's subscriptions
    643644 * @uses bbp_has_forums() To get the forums
    644645 * @uses apply_filters() Calls 'bbp_get_user_forum_subscriptions' with the forum
     
    647648 */
    648649function bbp_get_user_forum_subscriptions( $user_id = 0 ) {
    649 
    650     // Default to the displayed user
    651     $user_id       = bbp_get_user_id( $user_id );
    652     $subscriptions = bbp_get_user_subscribed_forum_ids( $user_id );
    653 
    654     // If user has subscriptions, load them
    655     if ( ! empty( $subscriptions ) ) {
    656         $query = bbp_has_forums( array( 'post__in' => $subscriptions ) );
    657     } else {
    658         $query = false;
    659     }
     650    $user_id = bbp_get_user_id( $user_id );
     651    $query   = bbp_has_forums( array(
     652        'meta_query' => array(
     653            array(
     654                'key'     => '_bbp_subscription',
     655                'value'   => $user_id,
     656                'compare' => 'NUMERIC'
     657            )
     658        )
     659    ) );
    660660
    661661    return apply_filters( 'bbp_get_user_forum_subscriptions', $query, $user_id );
Note: See TracChangeset for help on using the changeset viewer.