Skip to:
Content

BuddyPress.org

Changeset 2619


Ignore:
Timestamp:
02/07/2010 08:05:19 PM (17 years ago)
Author:
apeatling
Message:

Fixing missing cache calls.

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-activity.php

    r2573 r2619  
    471471        extract( $r, EXTR_SKIP );
    472472
    473         return apply_filters( 'bp_activity_get', BP_Activity_Activity::get( $max, $page, $per_page, $sort, $search_terms, $filter, $display_comments, $show_hidden ), &$r );
     473        /* Attempt to return a cached copy of the first page of sitewide activity. */
     474        if ( 1 == (int)$page && empty( $max ) && empty( $search_terms ) && empty( $filter ) && 'DESC' == $sort ) {
     475                if ( !$activity = wp_cache_get( 'bp_activity_sitewide_front', 'bp' ) ) {
     476                        $activity = BP_Activity_Activity::get( $max, $page, $per_page, $sort, $search_terms, $filter, $display_comments, $show_hidden );
     477                        wp_cache_set( 'bp_activity_sitewide_front', BP_Activity_Activity::get( $max, $page, $per_page, $sort, $search_terms, $filter, $display_comments, $show_hidden ), 'bp' );
     478                }
     479        } else
     480                $activity = BP_Activity_Activity::get( $max, $page, $per_page, $sort, $search_terms, $filter, $display_comments, $show_hidden );
     481
     482        return apply_filters( 'bp_activity_get', $activity, &$r );
    474483}
    475484
     
    546555                BP_Activity_Activity::rebuild_activity_comment_tree( $activity->item_id );
    547556
     557        wp_cache_delete( 'bp_activity_sitewide_front', 'bp' );
    548558        do_action( 'bp_activity_add', $params );
    549559
     
    629639        require_once( BP_PLUGIN_DIR . '/bp-activity/bp-activity-notifications.php' );
    630640        bp_activity_new_comment_notification( $comment_id, $user_id, $params );
     641
     642        /* Clear the comment cache for this activity */
     643        wp_cache_delete( 'bp_activity_comments_' . $parent_id );
    631644
    632645        do_action( 'bp_activity_comment_posted', $comment_id, $params );
     
    10151028        }
    10161029
    1017         wp_cache_replace( 'bp_activity_meta_' . $meta_key . '_' . $activity_id, $meta_value, 'bp' );
     1030        wp_cache_set( 'bp_activity_meta_' . $meta_key . '_' . $activity_id, $meta_value, 'bp' );
    10181031
    10191032        return true;
    10201033}
    1021 
    10221034
    10231035/**
  • trunk/bp-activity/bp-activity-classes.php

    r2616 r2619  
    335335                global $wpdb, $bp;
    336336
    337                 /* Select the user's fullname with the query so we don't have to fetch it for each comment */
    338                 if ( function_exists( 'xprofile_install' ) ) {
    339                         $fullname_select = ", pd.value as user_fullname";
    340                         $fullname_from = ", {$bp->profile->table_name_data} pd ";
    341                         $fullname_where = "AND pd.user_id = a.user_id AND pd.field_id = 1";
    342                 }
    343 
    344                 /* Retrieve all descendants of the $root node */
    345                 $descendants = $wpdb->get_results( $wpdb->prepare( "SELECT a.*, u.user_email, u.user_nicename, u.user_login, u.display_name{$fullname_select} FROM {$bp->activity->table_name} a, {$wpdb->users} u{$fullname_from} WHERE u.ID = a.user_id {$fullname_where} AND a.type = 'activity_comment' AND a.item_id = %d AND a.mptt_left BETWEEN %d AND %d ORDER BY a.date_recorded ASC", $activity_id, $left, $right ) );
    346 
    347                 /* Loop descendants and build an assoc array */
    348                 foreach ( (array)$descendants as $d ) {
    349                     $d->children = array();
    350 
    351                         /* If we have a reference on the parent */
    352                     if ( isset( $ref[ $d->secondary_item_id ] ) ) {
    353                         $ref[ $d->secondary_item_id ]->children[ $d->id ] = $d;
    354                         $ref[ $d->id ] =& $ref[ $d->secondary_item_id ]->children[ $d->id ];
    355 
    356                         /* If we don't have a reference on the parent, put in the root level */
    357                     } else {
    358                         $menu[ $d->id ] = $d;
    359                         $ref[ $d->id ] =& $menu[ $d->id ];
    360                     }
    361                 }
    362 
    363                 return $menu;
     337                if ( !$comments = wp_cache_get( 'bp_activity_comments_' . $activity_id ) ) {
     338                        /* Select the user's fullname with the query so we don't have to fetch it for each comment */
     339                        if ( function_exists( 'xprofile_install' ) ) {
     340                                $fullname_select = ", pd.value as user_fullname";
     341                                $fullname_from = ", {$bp->profile->table_name_data} pd ";
     342                                $fullname_where = "AND pd.user_id = a.user_id AND pd.field_id = 1";
     343                        }
     344
     345                        /* Retrieve all descendants of the $root node */
     346                        $descendants = $wpdb->get_results( $wpdb->prepare( "SELECT a.*, u.user_email, u.user_nicename, u.user_login, u.display_name{$fullname_select} FROM {$bp->activity->table_name} a, {$wpdb->users} u{$fullname_from} WHERE u.ID = a.user_id {$fullname_where} AND a.type = 'activity_comment' AND a.item_id = %d AND a.mptt_left BETWEEN %d AND %d ORDER BY a.date_recorded ASC", $activity_id, $left, $right ) );
     347
     348                        /* Loop descendants and build an assoc array */
     349                        foreach ( (array)$descendants as $d ) {
     350                            $d->children = array();
     351
     352                                /* If we have a reference on the parent */
     353                            if ( isset( $ref[ $d->secondary_item_id ] ) ) {
     354                                $ref[ $d->secondary_item_id ]->children[ $d->id ] = $d;
     355                                $ref[ $d->id ] =& $ref[ $d->secondary_item_id ]->children[ $d->id ];
     356
     357                                /* If we don't have a reference on the parent, put in the root level */
     358                            } else {
     359                                $comments[ $d->id ] = $d;
     360                                $ref[ $d->id ] =& $comments[ $d->id ];
     361                            }
     362                        }
     363                        wp_cache_set( 'bp_activity_comments_' . $activity_id, $comments, 'bp' );
     364                }
     365
     366                return $comments;
    364367        }
    365368
  • trunk/bp-core.php

    r2618 r2619  
    574574                return false;
    575575
    576         return apply_filters( 'bp_core_get_core_userdata', BP_Core_User::get_core_userdata( $user_id ) );
     576        if ( !$userdata = wp_cache_get( 'bp_core_userdata_' . $user_id, 'bp' ) ) {
     577                $userdata = BP_Core_User::get_core_userdata( $user_id );
     578                wp_cache_set( 'bp_core_userdata_' . $user_id, $userdata, 'bp' );
     579        }
     580        return apply_filters( 'bp_core_get_core_userdata', $userdata );
    577581}
    578582
  • trunk/bp-groups/bp-groups-classes.php

    r2582 r2619  
    281281                }
    282282
    283                 foreach ( (array)$paged_groups as $group ) $group_ids[] = $group->id;
    284                 $group_ids = $wpdb->escape( join( ',', (array)$group_ids ) );
    285                 $paged_groups = BP_Groups_Group::get_group_extras( &$paged_groups, $group_ids, 'newest' );
     283                if ( empty( $user_id ) ) {
     284                        foreach ( (array)$paged_groups as $group ) $group_ids[] = $group->id;
     285                        $group_ids = $wpdb->escape( join( ',', (array)$group_ids ) );
     286                        $paged_groups = BP_Groups_Group::get_group_extras( &$paged_groups, $group_ids, 'newest' );
     287                }
    286288
    287289                return array( 'groups' => $paged_groups, 'total' => $total_groups );
     
    311313                }
    312314
    313                 foreach ( (array)$paged_groups as $group ) $group_ids[] = $group->id;
    314                 $group_ids = $wpdb->escape( join( ',', (array)$group_ids ) );
    315                 $paged_groups = BP_Groups_Group::get_group_extras( &$paged_groups, $group_ids, 'active' );
     315                if ( empty( $user_id ) ) {
     316                        foreach ( (array)$paged_groups as $group ) $group_ids[] = $group->id;
     317                        $group_ids = $wpdb->escape( join( ',', (array)$group_ids ) );
     318                        $paged_groups = BP_Groups_Group::get_group_extras( &$paged_groups, $group_ids, 'newest' );
     319                }
    316320
    317321                return array( 'groups' => $paged_groups, 'total' => $total_groups );
     
    342346                }
    343347
    344                 foreach ( (array)$paged_groups as $group ) $group_ids[] = $group->id;
    345                 $group_ids = $wpdb->escape( join( ',', (array)$group_ids ) );
    346                 $paged_groups = BP_Groups_Group::get_group_extras( &$paged_groups, $group_ids, 'popular' );
     348                if ( empty( $user_id ) ) {
     349                        foreach ( (array)$paged_groups as $group ) $group_ids[] = $group->id;
     350                        $group_ids = $wpdb->escape( join( ',', (array)$group_ids ) );
     351                        $paged_groups = BP_Groups_Group::get_group_extras( &$paged_groups, $group_ids, 'newest' );
     352                }
    347353
    348354                return array( 'groups' => $paged_groups, 'total' => $total_groups );
     
    372378                }
    373379
    374                 foreach ( (array)$paged_groups as $group ) $group_ids[] = $group->id;
    375                 $group_ids = $wpdb->escape( join( ',', (array)$group_ids ) );
    376                 $paged_groups = BP_Groups_Group::get_group_extras( &$paged_groups, $group_ids, 'alphabetical' );
     380                if ( empty( $user_id ) ) {
     381                        foreach ( (array)$paged_groups as $group ) $group_ids[] = $group->id;
     382                        $group_ids = $wpdb->escape( join( ',', (array)$group_ids ) );
     383                        $paged_groups = BP_Groups_Group::get_group_extras( &$paged_groups, $group_ids, 'newest' );
     384                }
    377385
    378386                return array( 'groups' => $paged_groups, 'total' => $total_groups );
     
    406414                }
    407415
    408                 foreach ( (array)$paged_groups as $group ) $group_ids[] = $group->id;
    409                 $group_ids = $wpdb->escape( join( ',', (array)$group_ids ) );
    410                 $paged_groups = BP_Groups_Group::get_group_extras( &$paged_groups, $group_ids, 'most_forum_topics' );
     416                if ( empty( $user_id ) ) {
     417                        foreach ( (array)$paged_groups as $group ) $group_ids[] = $group->id;
     418                        $group_ids = $wpdb->escape( join( ',', (array)$group_ids ) );
     419                        $paged_groups = BP_Groups_Group::get_group_extras( &$paged_groups, $group_ids, 'newest' );
     420                }
    411421
    412422                return array( 'groups' => $paged_groups, 'total' => $total_groups );
     
    440450                }
    441451
    442                 foreach ( (array)$paged_groups as $group ) $group_ids[] = $group->id;
    443                 $group_ids = $wpdb->escape( join( ',', (array)$group_ids ) );
    444                 $paged_groups = BP_Groups_Group::get_group_extras( &$paged_groups, $group_ids, 'most_forum_posts' );
     452                if ( empty( $user_id ) ) {
     453                        foreach ( (array)$paged_groups as $group ) $group_ids[] = $group->id;
     454                        $group_ids = $wpdb->escape( join( ',', (array)$group_ids ) );
     455                        $paged_groups = BP_Groups_Group::get_group_extras( &$paged_groups, $group_ids, 'newest' );
     456                }
    445457
    446458                return array( 'groups' => $paged_groups, 'total' => $total_groups );
     
    509521                $paged_groups = $wpdb->get_results( $wpdb->prepare( "SELECT g.*, gm1.meta_value as total_member_count, gm2.meta_value as last_activity FROM {$bp->groups->table_name_groupmeta} gm1, {$bp->groups->table_name_groupmeta} gm2, {$bp->groups->table_name} g WHERE g.id = gm1.group_id AND g.id = gm2.group_id AND gm2.meta_key = 'last_activity' AND gm1.meta_key = 'total_member_count' AND g.name LIKE '$letter%%' {$hidden_sql} {$search_sql} ORDER BY g.name ASC {$pag_sql}"  ) );
    510522
    511                 foreach ( (array)$paged_groups as $group ) $group_ids[] = $group->id;
    512                 $group_ids = $wpdb->escape( join( ',', (array)$group_ids ) );
    513                 $paged_groups = BP_Groups_Group::get_group_extras( &$paged_groups, $group_ids, 'letter' );
     523                if ( empty( $user_id ) ) {
     524                        foreach ( (array)$paged_groups as $group ) $group_ids[] = $group->id;
     525                        $group_ids = $wpdb->escape( join( ',', (array)$group_ids ) );
     526                        $paged_groups = BP_Groups_Group::get_group_extras( &$paged_groups, $group_ids, 'newest' );
     527                }
    514528
    515529                return array( 'groups' => $paged_groups, 'total' => $total_groups );
     
    539553                }
    540554
    541                 foreach ( (array)$paged_groups as $group ) $group_ids[] = $group->id;
    542                 $group_ids = $wpdb->escape( join( ',', (array)$group_ids ) );
    543                 $paged_groups = BP_Groups_Group::get_group_extras( &$paged_groups, $group_ids, 'random' );
     555                if ( empty( $user_id ) ) {
     556                        foreach ( (array)$paged_groups as $group ) $group_ids[] = $group->id;
     557                        $group_ids = $wpdb->escape( join( ',', (array)$group_ids ) );
     558                        $paged_groups = BP_Groups_Group::get_group_extras( &$paged_groups, $group_ids, 'newest' );
     559                }
    544560
    545561                return array( 'groups' => $paged_groups, 'total' => $total_groups );
Note: See TracChangeset for help on using the changeset viewer.