Skip to:
Content

BuddyPress.org

Changeset 1238


Ignore:
Timestamp:
03/19/2009 01:35:32 PM (18 years ago)
Author:
apeatling
Message:

Added basic object caching support ready for the first release. This will cut the number of database calls and load by 3x. Add define( 'WP_CACHE', true ); to you wp-config.php and drop object-cache.php into /wp-content/ to enable.

A good file based object cache is available here:
​http://neosmart.net/dl.php?id=14

Location:
trunk
Files:
24 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-activity/bp-activity-templatetags.php

    r1193 r1238  
    3333
    3434                $this->activity_count = count($this->activities);
    35        
    3635                $this->full_name = $bp->displayed_user->fullname;
    3736
  • trunk/bp-activity/bp-activity-widgets.php

    r1052 r1238  
    2828        }
    2929        ?>
     30       
     31        <?php
     32        if ( !$activity = wp_cache_get( 'sitewide_activity', 'bp' ) ) {
     33                $activity = bp_activity_get_sitewide_activity( $options['max_items'] );
     34                wp_cache_set( 'sitewide_activity', $activity, 'bp' );
     35        }
     36        ?>
    3037
    31         <?php $activity = bp_activity_get_sitewide_activity( $options['max_items'] ) ?>
     38        <?php ?>
    3239       
    3340        <?php if ( $activity ) : ?>
  • trunk/bp-blogs.php

    r1227 r1238  
    466466                        bp_blogs_record_post( $post_id );
    467467                }
     468               
     469                $recorded_post = $existing_post;
    468470        }
    469471
    … …  
    623625        bp_blogs_delete_activity( array( 'item_id' => $post->blog_id, 'secondary_item_id' => $post->id, 'component_name' => 'blogs', 'component_action' => 'new_blog_post', 'user_id' => $post->user_id ) );
    624626
    625         do_action( 'bp_blogs_remove_post', $blog_id, $post_id );
     627        do_action( 'bp_blogs_remove_post', $blog_id, $post_id, $post->user_id );
    626628}
    627629add_action( 'delete_post', 'bp_blogs_remove_post' );
    … …  
    643645        bp_blogs_delete_activity( array( 'item_id' => $blog_id, 'secondary_item_id' => $comment_id, 'component_name' => 'blogs', 'component_action' => 'new_blog_comment', 'user_id' => $bp->loggedin_user->id ) );
    644646
    645         do_action( 'bp_blogs_remove_comment', $blog_id, $comment_id );
     647        do_action( 'bp_blogs_remove_comment', $blog_id, $comment_id, $bp->loggedin_user->id );
    646648}
    647649add_action( 'delete_comment', 'bp_blogs_remove_comment' );
    … …  
    834836add_action( 'wpmu_delete_user', 'bp_blogs_remove_data', 1 );
    835837add_action( 'delete_user', 'bp_blogs_remove_data', 1 );
     838
     839
     840function bp_blogs_clear_blog_object_cache( $blog_id, $user_id ) {
     841        wp_cache_delete( 'bp_user_blogs_' . $user_id, 'bp' );
     842}
     843
     844function bp_blogs_format_clear_blog_cache( $recorded_blog_obj ) {
     845        bp_blogs_clear_blog_object_cache( false, $recorded_blog_obj->user_id );
     846}
     847
     848function bp_blogs_clear_post_object_cache( $blog_id, $post_id, $user_id ) {
     849        wp_cache_delete( 'bp_user_posts_' . $user_id, 'bp' );
     850}
     851
     852function bp_blogs_format_clear_post_cache( $recorded_post_obj ) {
     853        bp_blogs_clear_post_object_cache( false, false, $recorded_post_obj->user_id );
     854}
     855
     856function bp_blogs_clear_comment_object_cache( $blog_id, $comment_id, $user_id ) {
     857        wp_cache_delete( 'bp_user_comments_' . $user_id, 'bp' );
     858}
     859
     860function bp_blogs_format_clear_comment_cache( $recorded_comment_obj ) {
     861        bp_blogs_clear_comment_object_cache( false, false, $recorded_comment_obj->user_id );
     862}
     863
     864// List actions to clear object caches on
     865add_action( 'bp_blogs_remove_blog_for_user', 'bp_blogs_clear_blog_object_cache', 10, 2 );
     866add_action( 'bp_blogs_remove_post', 'bp_blogs_clear_post_object_cache', 10, 3 );
     867add_action( 'bp_blogs_remove_comment', 'bp_blogs_clear_comment_object_cache', 10, 3 );
     868
     869add_action( 'bp_blogs_new_blog', 'bp_blogs_format_clear_blog_cache', 10, 2 );
     870add_action( 'bp_blogs_new_blog_post', 'bp_blogs_format_clear_post_cache', 10, 2 );
     871add_action( 'bp_blogs_new_blog_comment', 'bp_blogs_format_clear_comment_cache', 10, 2 );
    836872
    837873// List actions to clear super cached pages on, if super cache is installed
    … …  
    844880add_action( 'bp_blogs_new_blog_post', 'bp_core_clear_cache' );
    845881add_action( 'bp_blogs_new_blog', 'bp_core_clear_cache' );
    846 add_action( 'bp_blogs_new_blog', 'bp_core_clear_cache' );
    847882add_action( 'bp_blogs_remove_data', 'bp_core_clear_cache' );
    848883
  • trunk/bp-blogs/bp-blogs-classes.php

    r1052 r1238  
    365365                        $total_post_count = $wpdb->get_var( $wpdb->prepare( "SELECT count(p.post_id) FROM {$bp->blogs->table_name_blog_posts} p LEFT JOIN {$wpdb->base_prefix}blogs b ON p.blog_id = b.blog_id WHERE b.deleted = 0 AND b.archived = '0' AND b.spam = 0 AND b.mature = 0 AND p.user_id = %d", $user_id) );                       
    366366                }
    367                        
    368                        
     367
    369368                for ( $i = 0; $i < count($post_ids); $i++ ) {
    370369                        $posts[$i] = BP_Blogs_Post::fetch_post_content($post_ids[$i]);
  • trunk/bp-blogs/bp-blogs-templatetags.php

    r1052 r1238  
    2525
    2626                $this->blogs = bp_blogs_get_blogs_for_user( $user_id );
     27               
     28                if ( !$this->blogs = wp_cache_get( 'bp_user_blogs_' . $user_id, 'bp' ) ) {
     29                        $this->blogs = bp_blogs_get_blogs_for_user( $user_id );
     30                        wp_cache_set( 'bp_user_blogs_' . $user_id, $this->blogs, 'bp' );
     31                }
     32               
    2733                $this->total_blog_count = (int)$this->blogs['count'];
    2834                $this->blogs = $this->blogs['blogs'];
    … …  
    141147                $this->pag_page = isset( $_GET['fpage'] ) ? intval( $_GET['fpage'] ) : 1;
    142148                $this->pag_num = isset( $_GET['num'] ) ? intval( $_GET['num'] ) : 5;
    143 
    144                 $this->posts = bp_blogs_get_posts_for_user( $user_id );
     149               
     150                if ( !$this->posts = wp_cache_get( 'bp_user_posts_' . $user_id, 'bp' ) ) {
     151                        $this->posts = bp_blogs_get_posts_for_user( $user_id );
     152                        wp_cache_set( 'bp_user_posts_' . $user_id, $this->posts, 'bp' );
     153                }
     154               
    145155                $this->total_post_count = (int)$this->posts['count'];
    146156                $this->posts = $this->posts['posts'];
    … …  
    489499                $this->pag_page = isset( $_GET['fpage'] ) ? intval( $_GET['fpage'] ) : 1;
    490500                $this->pag_num = isset( $_GET['num'] ) ? intval( $_GET['num'] ) : 5;
    491 
    492                 $this->comments = bp_blogs_get_comments_for_user( $user_id );
     501               
     502                if ( !$this->comments = wp_cache_get( 'bp_user_comments_' . $user_id, 'bp' ) ) {
     503                        $this->comments = bp_blogs_get_comments_for_user( $user_id );
     504                        wp_cache_set( 'bp_user_comments_' . $user_id, $this->comments, 'bp' );
     505                }
     506               
    493507                $this->total_comment_count = (int)$this->comments['count'];
    494508                $this->comments = $this->comments['comments'];
  • trunk/bp-core.php

    r1236 r1238  
    13411341
    13421342function bp_core_print_generation_time() {
     1343        global $wpdb;
    13431344        ?>
    13441345<!-- Generated in <?php timer_stop(1); ?> seconds. -->
    … …  
    13601361        /* Remove usermeta */
    13611362        delete_usermeta( $user_id, 'last_activity' );
     1363        wp_cache_flush();
    13621364}
    13631365add_action( 'wpmu_delete_user', 'bp_core_remove_data', 1 );
    13641366add_action( 'delete_user', 'bp_core_remove_data', 1 );
     1367
     1368function bp_core_clear_user_object_cache( $user_id ) {
     1369        wp_cache_delete( 'bp_user_' . $user_id, 'bp' );
     1370        wp_cache_delete( 'online_users' );
     1371        wp_cache_delete( 'newest_users' );
     1372}
     1373
     1374// List actions to clear object caches on
     1375add_action( 'bp_core_delete_avatar', 'bp_core_clear_user_object_cache' );
     1376add_action( 'bp_core_avatar_save', 'bp_core_clear_user_object_cache' );
    13651377
    13661378// List actions to clear super cached pages on, if super cache is installed
  • trunk/bp-core/bp-core-adminbar.php

    r1209 r1238  
    126126       
    127127                if ( function_exists('bp_blogs_install') ) {
    128                         $blogs = get_blogs_of_user( $bp->loggedin_user->id ); // find *all* blogs with any kind of role
     128                       
     129                        if ( !$blogs = wp_cache_get( 'bp_user_blogs_' . $bp->loggedin_user->id, 'bp' ) ) {
     130                                $blogs = get_blogs_of_user( $bp->loggedin_user->id );
     131                                wp_cache_set( 'bp_user_blogs_' . $bp->loggedin_user->id, $blogs, 'bp' );
     132                        }
    129133
    130134                        echo '<li id="bp-adminbar-blogs-menu"><a href="' . $bp->loggedin_user->domain . $bp->blogs->slug . '/my-blogs">';
  • trunk/bp-core/bp-core-ajax.php

    r1197 r1238  
    88        switch ( $_POST['filter'] ) {
    99                case 'newest-members':
    10                         $users = BP_Core_User::get_newest_users( $_POST['max-members'], 1 );
     10                        if ( !$users = wp_cache_get( 'newest_users', 'bp' ) ) {
     11                                $users = BP_Core_User::get_newest_users( $_POST['max-members'], 1 );
     12                                wp_cache_set( 'newest_users', $users, 'bp' );
     13                        }
    1114                break;
    1215                case 'recently-active-members':
    13                         $users = BP_Core_User::get_active_users( $_POST['max-members'], 1 );
     16                        if ( !$users = wp_cache_get( 'active_users', 'bp' ) ) {
     17                                $users = BP_Core_User::get_active_users( $_POST['max-members'], 1 );
     18                                wp_cache_set( 'active_users', $users, 'bp' );
     19                        }
    1420                break;
    1521                case 'popular-members':
    16                         $users = BP_Core_User::get_popular_users( $_POST['max-members'], 1 );
     22                        if ( !$users = wp_cache_get( 'popular_users', 'bp' ) ) {
     23                                $users = BP_Core_User::get_popular_users( $_POST['max-members'], 1 );
     24                                wp_cache_set( 'popular_users', $users, 'bp' );
     25                        }
    1726                break;
    1827        }
    … …  
    117126                               
    118127                                        <div class="action">
    119                                                 <?php bp_add_friend_button( $user->user_id ) ?>
     128                                                <?php if ( function_exists('bp_add_friend_button') ) : ?>
     129                                                    <?php bp_add_friend_button( $user->user_id ) ?>
     130                                                <?php endif; ?>
    120131                                                <div class="meta">
    121132                                                        <?php if ( $user_obj->total_friends ) echo $user_obj->total_friends ?><?php if ( $user_obj->total_blogs ) echo ', ' . $user_obj->total_blogs ?><?php if ( $user_obj->total_groups ) echo ', ' . $user_obj->total_groups ?>
  • trunk/bp-core/bp-core-avatars.php

    r1209 r1238  
    435435        }
    436436       
    437         do_action( 'bp_core_avatar_save', $old, $v1_href, $vars['v1_out'] );
     437        do_action( 'bp_core_avatar_save', $user_id, $old, $v1_href, $vars['v1_out'] );
    438438}
    439439
    … …  
    458458
    459459function bp_core_delete_avatar() {
    460         $old_v1 = get_usermeta( get_current_user_id(), 'bp_core_avatar_v1_path' );
    461         $old_v2 = get_usermeta( get_current_user_id(), 'bp_core_avatar_v2_path' );
    462        
    463         delete_usermeta( get_current_user_id(), 'bp_core_avatar_v1_path' );
    464         delete_usermeta( get_current_user_id(), 'bp_core_avatar_v2_path' );
    465        
    466         delete_usermeta( get_current_user_id(), 'bp_core_avatar_v1' );
    467         delete_usermeta( get_current_user_id(), 'bp_core_avatar_v2' );
     460        $user_id = get_current_user_id();
     461       
     462        $old_v1 = get_usermeta( $user_id, 'bp_core_avatar_v1_path' );
     463        $old_v2 = get_usermeta( $user_id, 'bp_core_avatar_v2_path' );
     464       
     465        delete_usermeta( $user_id, 'bp_core_avatar_v1_path' );
     466        delete_usermeta( $user_id, 'bp_core_avatar_v2_path' );
     467       
     468        delete_usermeta( $user_id, 'bp_core_avatar_v1' );
     469        delete_usermeta( $user_id, 'bp_core_avatar_v2' );
    468470       
    469471        // Remove the actual images
    … …  
    471473        @unlink($old_v2);
    472474       
    473         do_action( 'bp_core_delete_avatar', $old_v1, $old_v2 );
     475        do_action( 'bp_core_delete_avatar', $user_id, $old_v1, $old_v2 );
    474476}
    475477
  • trunk/bp-core/bp-core-templatetags.php

    r1232 r1238  
    232232function bp_fetch_user_fullname( $user_id = false, $echo = true ) {
    233233        global $bp;
    234 
     234       
    235235        if ( !$user_id )
    236236                $user_id = $bp->displayed_user->id;
    237 
    238         if ( function_exists('xprofile_install') ) {
    239                 $data = xprofile_get_field_data( BP_XPROFILE_FULLNAME_FIELD_NAME, $user_id );
    240 
    241                 if ( empty($data) ) {
     237       
     238        if ( !$fullname = wp_cache_get( 'bp_user_fullname_' . $user_id, 'bp' ) ) {
     239                if ( function_exists('xprofile_install') ) {
     240                        $fullname = bp_core_ucfirst( xprofile_get_field_data( BP_XPROFILE_FULLNAME_FIELD_NAME, $user_id ) );
     241
     242                        if ( empty($fullname) ) {
     243                                $ud = get_userdata($user_id);
     244                                $fullname = bp_core_ucfirst($ud->user_login);
     245
     246                                xprofile_set_field_data( BP_XPROFILE_FULLNAME_FIELD_NAME, $user_id, $data );
     247                        }
     248                } else {
    242249                        $ud = get_userdata($user_id);
    243                         $data = bp_core_ucfirst($ud->user_login);
    244                        
    245                         xprofile_set_field_data( BP_XPROFILE_FULLNAME_FIELD_NAME, $user_id, $data );
    246                 } else {
    247                         $data = bp_core_ucfirst($data);
     250                        $fullname = $ud->user_login;
    248251                }
    249         } else {
    250                 $ud = get_userdata($user_id);
    251                 $data = $ud->user_login;
     252
     253                wp_cache_set( 'bp_user_fullname_' . $user_id, $fullname, 'bp' );
    252254        }
    253255
    254256        if ( $echo )
    255                 echo apply_filters( 'bp_fetch_user_fullname', stripslashes( trim( $data ) ) );
     257                echo apply_filters( 'bp_fetch_user_fullname', stripslashes( trim( $fullname ) ) );
    256258        else
    257                 return apply_filters( 'bp_fetch_user_fullname', stripslashes ( trim ( $data ) ) );
     259                return apply_filters( 'bp_fetch_user_fullname', stripslashes ( trim ( $fullname ) ) );
    258260}
    259261
  • trunk/bp-core/bp-core-widgets.php

    r1209 r1238  
    9090                . $after_title; ?>
    9191       
    92         <?php $users = BP_Core_User::get_newest_users( $options['max_members'] ) ?>
     92        <?php
     93        if ( !$users = wp_cache_get( 'newest_users', 'bp' ) ) {
     94                $users = BP_Core_User::get_newest_users( $options['max_members'] );
     95                wp_cache_set( 'newest_users', $users, 'bp' );
     96        }
     97        ?>
    9398       
    9499        <?php if ( $users['users'] ) : ?>
    … …  
    120125                ?>
    121126               
    122                 <input type="hidden" name="bp_core_widget_members_max" id="bp_core_widget_members_max" value="<?php echo $options['max_members'] ?>" />
     127                <input type="hidden" name="members_widget_max" id="members_widget_max" value="<?php echo $options['max_members'] ?>" />
    123128               
    124129        <?php else: ?>
    … …  
    165170                . $widget_name
    166171                . $after_title; ?>
     172
     173        <?php
     174        if ( !$users = wp_cache_get( 'online_users', 'bp' ) ) {
     175                $users = BP_Core_User::get_online_users( $options['max_members'] );
     176                wp_cache_set( 'online_users', $users, 'bp' );
     177        }
     178        ?>
    167179
    168180        <?php $users = BP_Core_User::get_online_users($options['max_members']) ?>
  • trunk/bp-core/js/widget-members.js

    r1052 r1238  
    1111                                'cookie': encodeURIComponent(document.cookie),
    1212                                '_wpnonce': jQuery("input#_wpnonce-members").val(),
    13                                 'max-members': jQuery("input#bp_core_widget_members_max").val(),
     13                                'max-members': jQuery("input#members_widget_max").val(),
    1414                                'filter': jQuery(this).attr('id')
    1515                        },
  • trunk/bp-friends.php

    r1227 r1238  
    619619add_action( 'delete_user', 'friends_remove_data', 1 );
    620620
     621function friends_clear_friend_object_cache( $friendship_id ) {
     622        if ( !$friendship = new BP_Friends_Friendship( $friendship_id ) )
     623                return false;
     624
     625        wp_cache_delete( 'friends_friend_ids_' . $friendship->initiator_user_id, 'bp' );
     626        wp_cache_delete( 'friends_friend_ids_' . $friendship->friend_user_id, 'bp' );
     627        wp_cache_delete( 'popular_users', 'bp' );
     628}
     629
     630// List actions to clear object caches on
     631add_action( 'friends_friendship_accepted', 'friends_clear_friend_object_cache' );
     632add_action( 'friends_friendship_deleted', 'friends_clear_friend_object_cache' );
     633
    621634// List actions to clear super cached pages on, if super cache is installed
    622635add_action( 'friends_friendship_rejected', 'bp_core_clear_cache' );
  • trunk/bp-friends/bp-friends-templatetags.php

    r1205 r1238  
    106106                } else {
    107107                        $this->friendship = (object) $this->friendship;
    108                         $this->friendship->friend = new BP_Core_User( $this->friendship->user_id );
     108                       
     109                        if ( !$this->friendship->friend = wp_cache_get( 'bp_user_' . $this->friendship->user_id, 'bp' ) ) {
     110                                $this->friendship->friend = new BP_Core_User( $this->friendship->user_id );
     111                                wp_cache_set( 'bp_user_' . $this->friendship->user_id, $this->friendship->friend, 'bp' );
     112                        }
    109113                }
    110114               
    … …  
    339343        global $bp;
    340344       
    341         $friend_ids = BP_Friends_Friendship::get_random_friends( $bp->displayed_user->id );
     345        if ( !$friend_ids = wp_cache_get( 'friends_friend_ids_' . $bp->displayed_user->id, 'bp' ) ) {
     346                $friend_ids = BP_Friends_Friendship::get_random_friends( $bp->displayed_user->id );
     347                wp_cache_set( 'friends_friend_ids_' . $bp->displayed_user->id, $friend_ids, 'bp' );
     348        }
    342349?>     
    343350        <div class="info-group">
    … …  
    366373        global $bp;
    367374       
    368         $user_ids = BP_Core_User::get_random_users( $total_members );
     375        if ( !$user_ids = wp_cache_get( 'friends_random_users', 'bp' ) ) {
     376                $user_ids = BP_Core_User::get_random_users( $total_members );
     377                wp_cache_set( 'friends_random_users', $user_ids, 'bp' );
     378        }
    369379?>     
    370380        <?php if ( $user_ids['users'] ) { ?>
  • trunk/bp-groups.php

    r1227 r1238  
    706706                        }
    707707
    708                         do_action( 'groups_group_avatar_edited', $group_obj->id );
     708                        do_action( 'groups_group_avatar_updated', $group_obj->id );
    709709
    710710                        bp_core_redirect( site_url() . '/' . $bp->current_component . '/' . $bp->current_item . '/admin/group-avatar' );
    … …  
    23132313
    23142314
     2315function groups_clear_group_object_cache( $group_id ) {
     2316        wp_cache_delete( 'groups_group_nouserdata_' . $group_id, 'bp' );
     2317        wp_cache_delete( 'groups_group_' . $group_id, 'bp' );
     2318        wp_cache_delete( 'newest_groups', 'bp' );
     2319        wp_cache_delete( 'active_groups', 'bp' );
     2320        wp_cache_delete( 'popular_groups', 'bp' );
     2321        wp_cache_delete( 'groups_random_groups', 'bp' );
     2322}
     2323
     2324// List actions to clear object caches on
     2325add_action( 'groups_group_deleted', 'groups_clear_group_object_cache' );
     2326add_action( 'groups_settings_updated', 'groups_clear_group_object_cache' );
     2327add_action( 'groups_details_updated', 'groups_clear_group_object_cache' );
     2328add_action( 'groups_group_avatar_updated', 'groups_clear_group_object_cache' );
     2329
    23152330// List actions to clear super cached pages on, if super cache is installed
    23162331add_action( 'groups_new_wire_post', 'bp_core_clear_cache' );
  • trunk/bp-groups/bp-groups-ajax.php

    r1221 r1238  
    5959        switch ( $_POST['filter'] ) {
    6060                case 'newest-groups':
    61                         $groups = groups_get_newest( $_POST['max-groups'], 1 );
     61                        if ( !$groups = wp_cache_get( 'newest_groups', 'bp' ) ) {
     62                                $groups = groups_get_newest( $_POST['max-groups'], 1 );
     63                                wp_cache_set( 'newest_groups', $groups, 'bp' );
     64                        }
    6265                break;
    6366                case 'recently-active-groups':
    64                         $groups = groups_get_active( $_POST['max-groups'], 1 );
     67                        if ( !$groups = wp_cache_get( 'active_groups', 'bp' ) ) {
     68                                $groups = groups_get_active( $_POST['max-groups'], 1 );
     69                                wp_cache_set( 'active_groups', $groups, 'bp' );
     70                        }
    6571                break;
    6672                case 'popular-groups':
    67                         $groups = groups_get_popular( $_POST['max-groups'], 1 );
     73                        if ( !$groups = wp_cache_get( 'popular_groups', 'bp' ) ) {
     74                                $groups = groups_get_popular( $_POST['max-groups'], 1 );
     75                                wp_cache_set( 'popular_groups', $groups, 'bp' );
     76                        }
    6877                break;
    6978        }
    … …  
    7281                echo '0[[SPLIT]]'; // return valid result.
    7382       
    74                 foreach ( (array) $groups['groups'] as $group ) {
    75                         $group = new BP_Groups_Group( $group->group_id, false, false );
     83                foreach ( (array) $groups['groups'] as $group_id ) {
     84                        if ( !$group = wp_cache_get( 'groups_group_nouserdata_' . $group_id->group_id, 'bp' ) ) {
     85                                $group = new BP_Groups_Group( $group_id->group_id, false, false );
     86                                wp_cache_set( 'groups_group_nouserdata_' . $group_id->group_id, $group, 'bp' );
     87                        }       
    7688                ?>
    7789                        <li>
    … …  
    240252                <?php $counter = 0; ?>
    241253                <ul id="groups-list" class="item-list">
    242                 <?php foreach ( $groups['groups'] as $group ) : ?>
     254                <?php foreach ( $groups['groups'] as $group_id ) : ?>
    243255                       
    244256                        <?php $alt = ( $counter % 2 == 1 ) ? ' class="alt"' : ''; ?>
    245                         <?php $group = new BP_Groups_Group( $group->group_id, false, false ); ?>
     257                        <?php
     258                                if ( !$group = wp_cache_get( 'groups_group_nouserdata_' . $group_id->group_id, 'bp' ) ) {
     259                                        $group = new BP_Groups_Group( $group_id->group_id, false, false );
     260                                        wp_cache_set( 'groups_group_nouserdata_' . $group_id->group_id, $group, 'bp' );
     261                                }       
     262                        ?>
    246263                       
    247264                        <li<?php echo $alt ?>>
  • trunk/bp-groups/bp-groups-templatetags.php

    r1221 r1238  
    152152               
    153153                // If this is a single group then instantiate group meta when creating the object.
    154                 if ( $this->single_group )
    155                         $this->group = new BP_Groups_Group( $this->group->group_id, true );
    156                 else
    157                         $this->group = new BP_Groups_Group( $this->group->group_id, false, false );
    158 
     154                if ( $this->single_group ) {
     155                        if ( !$group = wp_cache_get( 'groups_group_' . $this->group->group_id, 'bp' ) ) {
     156                                $group = new BP_Groups_Group( $this->group->group_id, true );
     157                                wp_cache_set( 'groups_group_' . $this->group->group_id, $group, 'bp' );
     158                        }
     159                } else {
     160                        if ( !$group = wp_cache_get( 'groups_group_nouserdata_' . $this->group->group_id, 'bp' ) ) {
     161                                $group = new BP_Groups_Group( $this->group->group_id, false, false );
     162                                wp_cache_set( 'groups_group_nouserdata_' . $this->group->group_id, $group, 'bp' );
     163                        }
     164                }
     165               
     166                $this->group = $group;
     167               
    159168                if ( 0 == $this->current_group ) // loop has just started
    160169                        do_action('loop_start');
    … …  
    984993               
    985994                <ul id="friend-list" class="item-list">
    986                         <?php for( $i = 0; $i < count($invites); $i++ ) {
    987                                 $user = new BP_Core_User( $invites[$i] ); ?>
    988        
     995                        <?php for ( $i = 0; $i < count($invites); $i++ ) {
     996                                if ( !$user = wp_cache_get( 'bp_user_' . $invites[$i], 'bp' ) ) {
     997                                        $user = new BP_Core_User( $invites[$i] );
     998                                        wp_cache_set( 'bp_user_' . $invites[$i], $user, 'bp' );
     999                                }
     1000                                ?>
    9891001                                <li id="uid-<?php echo $user->id ?>">
    9901002                                        <?php echo $user->avatar_thumb ?>
    … …  
    13561368        global $bp;
    13571369       
    1358         $group_ids = BP_Groups_Group::get_random( $total_groups, 1 );
     1370        if ( !$group_ids = wp_cache_get( 'groups_random_groups', 'bp' ) ) {
     1371                $group_ids = BP_Groups_Group::get_random( $total_groups, 1 );
     1372                wp_cache_set( 'groups_random_groups', $group_ids, 'bp' );
     1373        }
    13591374?>     
    13601375        <?php if ( $group_ids['groups'] ) { ?>
    13611376                <ul class="item-list" id="random-groups-list">
    1362                 <?php for ( $i = 0; $i < count( $group_ids['groups'] ); $i++ ) { ?>
    1363                         <?php $group = new BP_Groups_Group( $group_ids['groups'][$i]->group_id, false, false ); ?>
     1377                <?php
     1378                        for ( $i = 0; $i < count( $group_ids['groups'] ); $i++ ) {
     1379                                if ( !$group = wp_cache_get( 'groups_group_nouserdata_' . $group_ids['groups'][$i]->group_id, 'bp' ) ) {
     1380                                        $group = new BP_Groups_Group( $group_ids['groups'][$i]->group_id, false, false );
     1381                                        wp_cache_set( 'groups_group_nouserdata_' . $group_ids['groups'][$i]->group_id, $group, 'bp' );
     1382                                }
     1383                        ?>     
    13641384                        <li>
    13651385                                <div class="item-avatar">
    … …  
    14011421        global $bp;
    14021422       
    1403         $group_ids = groups_get_random_groups_for_user( $bp->displayed_user->id, $total_groups, 1 );
     1423        if ( !$group_ids = wp_cache_get( 'groups_random_user_groups_' . $bp->displayed_user->id . '_' . $total_groups, 'bp' ) ) {
     1424                $group_ids = groups_get_random_groups_for_user( $bp->displayed_user->id, $total_groups, 1 );
     1425                wp_cache_set( 'groups_random_user_groups_' . $bp->displayed_user->id . '_' . $total_groups, $group_ids, 'bp' );
     1426        }
     1427       
    14041428?>     
    14051429        <div class="info-group">
    … …  
    14071431                <?php if ( $group_ids ) { ?>
    14081432                        <ul class="horiz-gallery">
    1409                         <?php for ( $i = 0; $i < count( $group_ids ); $i++ ) { ?>
    1410                                 <?php $group = new BP_Groups_Group( $group_ids[$i], false, false ); ?>
    1411                                 <li>
     1433                        <?php
     1434                        for ( $i = 0; $i < count( $group_ids ); $i++ ) {
     1435                                if ( !$group = wp_cache_get( 'groups_group_nouserdata_' . $group_ids[$i], 'bp' ) ) {
     1436                                        $group = new BP_Groups_Group( $group_ids[$i], false, false );
     1437                                        wp_cache_set( 'groups_group_nouserdata_' . $group_ids[$i], $group, 'bp' );
     1438                                }
     1439                        ?>                              <li>
    14121440                                        <a href="<?php echo bp_group_permalink( $group, false ) ?>"><img src="<?php echo $group->avatar_thumb; ?>" class="avatar" alt="<?php _e( 'Group Avatar', 'buddypress' ) ?>" /></a>
    14131441                                        <h5><a href="<?php echo bp_group_permalink( $group, false ) ?>"><?php echo $group->name ?></a></h5>
  • trunk/bp-groups/bp-groups-widgets.php

    r1221 r1238  
    2828                . $widget_name
    2929                . $after_title; ?>
    30        
    31         <?php $groups = groups_get_popular( $options['max_groups'], 1 ); ?>
    32        
     30
     31        <?php
     32        if ( !$groups = wp_cache_get( 'popular_groups', 'bp' ) ) {
     33                $groups = groups_get_popular( $options['max_groups'], 1 );
     34                wp_cache_set( 'popular_groups', $groups, 'bp' );
     35        }
     36        ?>
     37
    3338        <?php if ( $groups['groups'] ) : ?>
    3439                <div class="item-options" id="groups-list-options">
    … …  
    3944                </div>
    4045                <ul id="groups-list" class="item-list">
    41                         <?php foreach ( $groups['groups'] as $group ) : ?>
    42                                 <?php $group = new BP_Groups_Group( $group->group_id, false, false ) ?>
     46                        <?php foreach ( $groups['groups'] as $group_id ) : ?>
     47                                <?php
     48                                if ( !$group = wp_cache_get( 'groups_group_nouserdata_' . $group_id->group_id, 'bp' ) ) {
     49                                        $group = new BP_Groups_Group( $group_id->group_id, false, false );
     50                                        wp_cache_set( 'groups_group_nouserdata_' . $group_id->group_id, $group, 'bp' );
     51                                }       
     52                                ?>
    4353                                <li>
    4454                                        <div class="item-avatar">
    … …  
    6878                ?>
    6979               
    70                 <input type="hidden" name="groups_widget_groups_list_max_groups" id="groups_widget_groups_list_max_groups" value="<?php echo $options['max_groups'] ?>" />
     80                <input type="hidden" name="groups_widget_max" id="groups_widget_max" value="<?php echo $options['max_groups'] ?>" />
    7181               
    7282        <?php else: ?>
  • trunk/bp-groups/directories/bp-groups-directory-groups.php

    r1209 r1238  
    100100
    101101                        <ul id="groups-list" class="item-list">
    102                         <?php foreach ( $groups['groups'] as $group ) : ?>
    103                                 <?php $group = new BP_Groups_Group( $group->group_id, false, false ); ?>
     102                        <?php foreach ( $groups['groups'] as $group_id ) : ?>
     103                                <?php
     104                                        if ( !$group = wp_cache_get( 'groups_group_nouserdata_' . $group_id->group_id, 'bp' ) ) {
     105                                                $group = new BP_Groups_Group( $group_id->group_id, false, false );
     106                                                wp_cache_set( 'groups_group_nouserdata_' . $group_id->group_id, $group, 'bp' );
     107                                        }       
     108                                ?>
    104109                                <li>
    105110                                        <div class="item-avatar">
    … …  
    175180                <?php if ( $groups['groups'] ) { ?>
    176181                        <ul id="featured-group-list" class="item-list">
    177                                 <?php foreach( $groups['groups'] as $group ) : ?>
    178                                         <?php $group = new BP_Groups_Group( $group->group_id, false, false ); ?>
     182                                <?php foreach( $groups['groups'] as $group_id ) : ?>
     183                                        <?php
     184                                                if ( !$group = wp_cache_get( 'groups_group_nouserdata_' . $group_id->group_id, 'bp' ) ) {
     185                                                        $group = new BP_Groups_Group( $group_id->group_id, false, false );
     186                                                        wp_cache_set( 'groups_group_nouserdata_' . $group_id->group_id, $group, 'bp' );
     187                                                }       
     188                                        ?>
    179189                                        <li>
    180190                                                <div class="item-avatar">
  • trunk/bp-groups/js/widget-groups.js

    r1052 r1238  
    1111                                'cookie': encodeURIComponent(document.cookie),
    1212                                '_wpnonce': jQuery("input#_wpnonce-groups").val(),
    13                                 'max-groups': jQuery("input#groups_widget_groups_list_max_groups").val(),
     13                                'max-groups': jQuery("input#groups_widget_max").val(),
    1414                                'filter': jQuery(this).attr('id')
    1515                        },
  • trunk/bp-wire/bp-wire-classes.php

    r1052 r1238  
    9595                        $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
    9696               
    97                 $wire_posts = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$table_name} WHERE item_id = %d  ORDER BY date_posted DESC $pag_sql", $item_id ) );
     97                $wire_posts = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$table_name} WHERE item_id = %d ORDER BY date_posted DESC $pag_sql", $item_id ) );
    9898                $count = $wpdb->get_var( $wpdb->prepare( "SELECT count(id) FROM {$table_name} WHERE item_id = %d", $item_id ) );
    9999               
  • trunk/bp-xprofile.php

    r1230 r1238  
    622622 * handling the save action.
    623623 *
    624  * [NOTE] This is old code that was written when support for the admin area was also
    625  * available. It is big and clunky and needs to be broken up.
     624 * [NOTE] This is old code that was written when editing was not done in the theme.
     625 * It is big and clunky and will be broken up in future versions.
    626626 *
    627627 * @package BuddyPress XProfile
    … …  
    965965add_action( 'delete_user', 'xprofile_remove_data', 1 );
    966966
     967
     968function xprofile_clear_profile_groups_object_cache( $group_obj ) {
     969        wp_cache_delete( 'xprofile_groups', 'bp' );
     970        wp_cache_delete( 'xprofile_groups_inc_empty', 'bp' );
     971        wp_cache_delete( 'xprofile_group_' . $group_obj->id );
     972}
     973
     974function xprofile_clear_profile_data_object_cache( $group_id ) {
     975        global $bp;     
     976        wp_cache_delete( 'xprofile_fields_' . $group_id . '_' . $bp->loggedin_user->id, 'bp' );
     977        wp_cache_delete( 'online_users', 'bp' );
     978        wp_cache_delete( 'newest_users', 'bp' );
     979        wp_cache_delete( 'popular_users', 'bp' );
     980}
     981
     982// List actions to clear object caches on
     983add_action( 'xprofile_groups_deleted_group', 'xprofile_clear_profile_groups_object_cache' );
     984add_action( 'xprofile_groups_saved_group', 'xprofile_clear_profile_groups_object_cache' );
     985add_action( 'xprofile_updated_profile', 'xprofile_clear_profile_data_object_cache' );
     986
    967987// List actions to clear super cached pages on, if super cache is installed
    968988add_action( 'xprofile_updated_profile', 'bp_core_clear_cache' );
  • trunk/bp-xprofile/bp-xprofile-admin.php

    r1141 r1238  
    154154                                $message = __('The group was saved successfully.', 'buddypress');
    155155                                $type = 'success';
     156                               
     157                                do_action( 'xprofile_groups_saved_group', $group );
    156158                        }
    157159                       
    … …  
    184186                $message = __('The group was deleted successfully.', 'buddypress');
    185187                $type = 'success';
     188               
     189                do_action( 'xprofile_groups_deleted_group', $group );
    186190        }
    187191       
    … …  
    224228                                unset($_GET['mode']);
    225229                               
    226                                 $groups = $groups = BP_XProfile_Group::get_all();
     230                                do_action( 'xprofile_fields_saved_field', $field );
     231                               
     232                                $groups = BP_XProfile_Group::get_all();
    227233                                xprofile_admin( $message, $type );
    228234                        }
    … …  
    258264                $message = sprintf( __('The %s was deleted successfully!', 'buddypress'), $type);
    259265                $type = 'success';
     266               
     267                do_action( 'xprofile_fields_deleted_field', $field );
    260268        }
    261269       
  • trunk/bp-xprofile/bp-xprofile-templatetags.php

    r1224 r1238  
    1717
    1818        function bp_xprofile_template($user_id) {
    19                 $this->groups = BP_XProfile_Group::get_all(true);
     19                if ( !$this->groups = wp_cache_get( 'xprofile_groups', 'bp' ) ) {
     20                        $this->groups = BP_XProfile_Group::get_all(true);
     21                        wp_cache_set( 'xprofile_groups', $this->groups, 'bp' );
     22                }
     23
    2024                $this->group_count = count($this->groups);
    2125                $this->user_id = $user_id;
    … …  
    3539                $this->field_count = count($this->group->fields);
    3640               
    37                 for ( $i = 0; $i < $this->field_count; $i++ ) {
    38                         $this->group->fields[$i] = new BP_XProfile_Field( $this->group->fields[$i]->id, $this->user_id );       
    39                 }
     41                if ( !$fields = wp_cache_get( 'xprofile_fields_' . $this->group->id . '_' . $this->user_id, 'bp' ) ) {
     42                        for ( $i = 0; $i < $this->field_count; $i++ ) {
     43                                $field = new BP_XProfile_Field( $this->group->fields[$i]->id, $this->user_id );
     44                                $fields[$i] = $field;
     45                        }
     46                       
     47                        wp_cache_set( 'xprofile_fields_' . $this->group->id . '_' . $this->user_id, $fields, 'bp' );
     48                }
     49               
     50                $this->group->fields = $fields;
    4051               
    4152                return $this->group;
    … …  
    227238        global $bp, $group_name;
    228239       
    229         $groups = BP_XProfile_Group::get_all();
    230        
     240        if ( !$groups = wp_cache_get( 'xprofile_groups_inc_empty', 'bp' ) ) {
     241                $groups = BP_XProfile_Group::get_all();
     242                wp_cache_set( 'xprofile_groups_inc_empty', $groups, 'bp' );
     243        }
     244
    231245        if ( empty( $group_name ) )
    232246                $group_name = bp_profile_group_name(false);
    … …  
    253267                $group_id = 1;
    254268       
    255         $group = new BP_XProfile_Group($group_id);
     269        if ( !$group = wp_cache_get( 'xprofile_group_' . $group_id, 'bp' ) ) {
     270                $group = new BP_XProfile_Group($group_id);
     271                wp_cache_set( 'xprofile_group_' . $group_id, $group, 'bp' );
     272        }
    256273       
    257274        if ( $echo ) {
Note: See TracChangeset for help on using the changeset viewer.