<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><style type="text/css"><!--
#msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fc0 solid; padding: 6px; }
#msg ul, pre { overflow: auto; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<title>[BuddyPress] [2619] trunk: Fixing missing cache calls.</title>
</head>
<body>

<div id="msg">
<dl>
<dt>Revision</dt> <dd>2619</dd>
<dt>Author</dt> <dd>apeatling</dd>
<dt>Date</dt> <dd>2010-02-07 20:05:19 +0000 (Sun, 07 Feb 2010)</dd>
</dl>

<h3>Log Message</h3>
<pre>Fixing missing cache calls.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkbpactivitybpactivityclassesphp">trunk/bp-activity/bp-activity-classes.php</a></li>
<li><a href="#trunkbpactivityphp">trunk/bp-activity.php</a></li>
<li><a href="#trunkbpcorephp">trunk/bp-core.php</a></li>
<li><a href="#trunkbpgroupsbpgroupsclassesphp">trunk/bp-groups/bp-groups-classes.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkbpactivitybpactivityclassesphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-activity/bp-activity-classes.php (2618 => 2619)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-activity/bp-activity-classes.php        2010-02-07 15:39:34 UTC (rev 2618)
+++ trunk/bp-activity/bp-activity-classes.php        2010-02-07 20:05:19 UTC (rev 2619)
</span><span class="lines">@@ -334,33 +334,36 @@
</span><span class="cx">         function get_activity_comments( $activity_id, $left, $right ) {
</span><span class="cx">                 global $wpdb, $bp;
</span><span class="cx"> 
</span><del>-                /* Select the user's fullname with the query so we don't have to fetch it for each comment */
-                if ( function_exists( 'xprofile_install' ) ) {
-                        $fullname_select = &quot;, pd.value as user_fullname&quot;;
-                        $fullname_from = &quot;, {$bp-&gt;profile-&gt;table_name_data} pd &quot;;
-                        $fullname_where = &quot;AND pd.user_id = a.user_id AND pd.field_id = 1&quot;;
-                }
</del><ins>+                if ( !$comments = wp_cache_get( 'bp_activity_comments_' . $activity_id ) ) {
+                        /* Select the user's fullname with the query so we don't have to fetch it for each comment */
+                        if ( function_exists( 'xprofile_install' ) ) {
+                                $fullname_select = &quot;, pd.value as user_fullname&quot;;
+                                $fullname_from = &quot;, {$bp-&gt;profile-&gt;table_name_data} pd &quot;;
+                                $fullname_where = &quot;AND pd.user_id = a.user_id AND pd.field_id = 1&quot;;
+                        }
</ins><span class="cx"> 
</span><del>-                /* Retrieve all descendants of the $root node */
-                $descendants = $wpdb-&gt;get_results( $wpdb-&gt;prepare( &quot;SELECT a.*, u.user_email, u.user_nicename, u.user_login, u.display_name{$fullname_select} FROM {$bp-&gt;activity-&gt;table_name} a, {$wpdb-&gt;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&quot;, $activity_id, $left, $right ) );
</del><ins>+                        /* Retrieve all descendants of the $root node */
+                        $descendants = $wpdb-&gt;get_results( $wpdb-&gt;prepare( &quot;SELECT a.*, u.user_email, u.user_nicename, u.user_login, u.display_name{$fullname_select} FROM {$bp-&gt;activity-&gt;table_name} a, {$wpdb-&gt;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&quot;, $activity_id, $left, $right ) );
</ins><span class="cx"> 
</span><del>-                /* Loop descendants and build an assoc array */
-                foreach ( (array)$descendants as $d ) {
-                    $d-&gt;children = array();
</del><ins>+                        /* Loop descendants and build an assoc array */
+                        foreach ( (array)$descendants as $d ) {
+                            $d-&gt;children = array();
</ins><span class="cx"> 
</span><del>-                        /* If we have a reference on the parent */
-                    if ( isset( $ref[ $d-&gt;secondary_item_id ] ) ) {
-                        $ref[ $d-&gt;secondary_item_id ]-&gt;children[ $d-&gt;id ] = $d;
-                        $ref[ $d-&gt;id ] =&amp; $ref[ $d-&gt;secondary_item_id ]-&gt;children[ $d-&gt;id ];
</del><ins>+                                /* If we have a reference on the parent */
+                            if ( isset( $ref[ $d-&gt;secondary_item_id ] ) ) {
+                                $ref[ $d-&gt;secondary_item_id ]-&gt;children[ $d-&gt;id ] = $d;
+                                $ref[ $d-&gt;id ] =&amp; $ref[ $d-&gt;secondary_item_id ]-&gt;children[ $d-&gt;id ];
</ins><span class="cx"> 
</span><del>-                        /* If we don't have a reference on the parent, put in the root level */
-                    } else {
-                        $menu[ $d-&gt;id ] = $d;
-                        $ref[ $d-&gt;id ] =&amp; $menu[ $d-&gt;id ];
-                    }
</del><ins>+                                /* If we don't have a reference on the parent, put in the root level */
+                            } else {
+                                $comments[ $d-&gt;id ] = $d;
+                                $ref[ $d-&gt;id ] =&amp; $comments[ $d-&gt;id ];
+                            }
+                        }
+                        wp_cache_set( 'bp_activity_comments_' . $activity_id, $comments, 'bp' );
</ins><span class="cx">                 }
</span><span class="cx"> 
</span><del>-                return $menu;
</del><ins>+                return $comments;
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         function rebuild_activity_comment_tree( $parent_id, $left = 1 ) {
</span></span></pre></div>
<a id="trunkbpactivityphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-activity.php (2618 => 2619)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-activity.php        2010-02-07 15:39:34 UTC (rev 2618)
+++ trunk/bp-activity.php        2010-02-07 20:05:19 UTC (rev 2619)
</span><span class="lines">@@ -470,7 +470,16 @@
</span><span class="cx">         $r = wp_parse_args( $args, $defaults );
</span><span class="cx">         extract( $r, EXTR_SKIP );
</span><span class="cx"> 
</span><del>-        return apply_filters( 'bp_activity_get', BP_Activity_Activity::get( $max, $page, $per_page, $sort, $search_terms, $filter, $display_comments, $show_hidden ), &amp;$r );
</del><ins>+        /* Attempt to return a cached copy of the first page of sitewide activity. */
+        if ( 1 == (int)$page &amp;&amp; empty( $max ) &amp;&amp; empty( $search_terms ) &amp;&amp; empty( $filter ) &amp;&amp; 'DESC' == $sort ) {
+                if ( !$activity = wp_cache_get( 'bp_activity_sitewide_front', 'bp' ) ) {
+                        $activity = BP_Activity_Activity::get( $max, $page, $per_page, $sort, $search_terms, $filter, $display_comments, $show_hidden );
+                        wp_cache_set( 'bp_activity_sitewide_front', BP_Activity_Activity::get( $max, $page, $per_page, $sort, $search_terms, $filter, $display_comments, $show_hidden ), 'bp' );
+                }
+        } else
+                $activity = BP_Activity_Activity::get( $max, $page, $per_page, $sort, $search_terms, $filter, $display_comments, $show_hidden );
+
+        return apply_filters( 'bp_activity_get', $activity, &amp;$r );
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> function bp_activity_get_specific( $args = '' ) {
</span><span class="lines">@@ -545,6 +554,7 @@
</span><span class="cx">         if ( 'activity_comment' == $activity-&gt;type )
</span><span class="cx">                 BP_Activity_Activity::rebuild_activity_comment_tree( $activity-&gt;item_id );
</span><span class="cx"> 
</span><ins>+        wp_cache_delete( 'bp_activity_sitewide_front', 'bp' );
</ins><span class="cx">         do_action( 'bp_activity_add', $params );
</span><span class="cx"> 
</span><span class="cx">         return $activity-&gt;id;
</span><span class="lines">@@ -629,6 +639,9 @@
</span><span class="cx">         require_once( BP_PLUGIN_DIR . '/bp-activity/bp-activity-notifications.php' );
</span><span class="cx">         bp_activity_new_comment_notification( $comment_id, $user_id, $params );
</span><span class="cx"> 
</span><ins>+        /* Clear the comment cache for this activity */
+        wp_cache_delete( 'bp_activity_comments_' . $parent_id );
+
</ins><span class="cx">         do_action( 'bp_activity_comment_posted', $comment_id, $params );
</span><span class="cx"> 
</span><span class="cx">         return $comment_id;
</span><span class="lines">@@ -1014,12 +1027,11 @@
</span><span class="cx">                 return false;
</span><span class="cx">         }
</span><span class="cx"> 
</span><del>-        wp_cache_replace( 'bp_activity_meta_' . $meta_key . '_' . $activity_id, $meta_value, 'bp' );
</del><ins>+        wp_cache_set( 'bp_activity_meta_' . $meta_key . '_' . $activity_id, $meta_value, 'bp' );
</ins><span class="cx"> 
</span><span class="cx">         return true;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-
</del><span class="cx"> /**
</span><span class="cx">  * bp_activity_filter_template_paths()
</span><span class="cx">  *
</span></span></pre></div>
<a id="trunkbpcorephp"></a>
<div class="modfile"><h4>Modified: trunk/bp-core.php (2618 => 2619)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-core.php        2010-02-07 15:39:34 UTC (rev 2618)
+++ trunk/bp-core.php        2010-02-07 20:05:19 UTC (rev 2619)
</span><span class="lines">@@ -573,7 +573,11 @@
</span><span class="cx">         if ( empty( $user_id ) )
</span><span class="cx">                 return false;
</span><span class="cx"> 
</span><del>-        return apply_filters( 'bp_core_get_core_userdata', BP_Core_User::get_core_userdata( $user_id ) );
</del><ins>+        if ( !$userdata = wp_cache_get( 'bp_core_userdata_' . $user_id, 'bp' ) ) {
+                $userdata = BP_Core_User::get_core_userdata( $user_id );
+                wp_cache_set( 'bp_core_userdata_' . $user_id, $userdata, 'bp' );
+        }
+        return apply_filters( 'bp_core_get_core_userdata', $userdata );
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> /**
</span></span></pre></div>
<a id="trunkbpgroupsbpgroupsclassesphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-groups/bp-groups-classes.php (2618 => 2619)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-groups/bp-groups-classes.php        2010-02-07 15:39:34 UTC (rev 2618)
+++ trunk/bp-groups/bp-groups-classes.php        2010-02-07 20:05:19 UTC (rev 2619)
</span><span class="lines">@@ -280,9 +280,11 @@
</span><span class="cx">                         $total_groups = $wpdb-&gt;get_var( &quot;SELECT COUNT(DISTINCT g.id) FROM {$bp-&gt;groups-&gt;table_name_groupmeta} gm INNER JOIN {$bp-&gt;groups-&gt;table_name} g ON gm.group_id = g.id WHERE gm.meta_key = 'last_activity'{$hidden_sql} {$search_sql}&quot; );
</span><span class="cx">                 }
</span><span class="cx"> 
</span><del>-                foreach ( (array)$paged_groups as $group ) $group_ids[] = $group-&gt;id;
-                $group_ids = $wpdb-&gt;escape( join( ',', (array)$group_ids ) );
-                $paged_groups = BP_Groups_Group::get_group_extras( &amp;$paged_groups, $group_ids, 'newest' );
</del><ins>+                if ( empty( $user_id ) ) {
+                        foreach ( (array)$paged_groups as $group ) $group_ids[] = $group-&gt;id;
+                        $group_ids = $wpdb-&gt;escape( join( ',', (array)$group_ids ) );
+                        $paged_groups = BP_Groups_Group::get_group_extras( &amp;$paged_groups, $group_ids, 'newest' );
+                }
</ins><span class="cx"> 
</span><span class="cx">                 return array( 'groups' =&gt; $paged_groups, 'total' =&gt; $total_groups );
</span><span class="cx">         }
</span><span class="lines">@@ -310,9 +312,11 @@
</span><span class="cx">                         $total_groups = $wpdb-&gt;get_var( &quot;SELECT COUNT(DISTINCT g.id) FROM {$bp-&gt;groups-&gt;table_name_groupmeta} gm INNER JOIN {$bp-&gt;groups-&gt;table_name} g ON gm.group_id = g.id WHERE gm.meta_key = 'last_activity'{$hidden_sql} {$search_sql}&quot; );
</span><span class="cx">                 }
</span><span class="cx"> 
</span><del>-                foreach ( (array)$paged_groups as $group ) $group_ids[] = $group-&gt;id;
-                $group_ids = $wpdb-&gt;escape( join( ',', (array)$group_ids ) );
-                $paged_groups = BP_Groups_Group::get_group_extras( &amp;$paged_groups, $group_ids, 'active' );
</del><ins>+                if ( empty( $user_id ) ) {
+                        foreach ( (array)$paged_groups as $group ) $group_ids[] = $group-&gt;id;
+                        $group_ids = $wpdb-&gt;escape( join( ',', (array)$group_ids ) );
+                        $paged_groups = BP_Groups_Group::get_group_extras( &amp;$paged_groups, $group_ids, 'newest' );
+                }
</ins><span class="cx"> 
</span><span class="cx">                 return array( 'groups' =&gt; $paged_groups, 'total' =&gt; $total_groups );
</span><span class="cx">         }
</span><span class="lines">@@ -341,9 +345,11 @@
</span><span class="cx">                         $total_groups = $wpdb-&gt;get_var( &quot;SELECT COUNT(DISTINCT g.id) FROM {$bp-&gt;groups-&gt;table_name_groupmeta} gm1, {$bp-&gt;groups-&gt;table_name_groupmeta} gm2, {$bp-&gt;groups-&gt;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' {$hidden_sql} {$search_sql}&quot; );
</span><span class="cx">                 }
</span><span class="cx"> 
</span><del>-                foreach ( (array)$paged_groups as $group ) $group_ids[] = $group-&gt;id;
-                $group_ids = $wpdb-&gt;escape( join( ',', (array)$group_ids ) );
-                $paged_groups = BP_Groups_Group::get_group_extras( &amp;$paged_groups, $group_ids, 'popular' );
</del><ins>+                if ( empty( $user_id ) ) {
+                        foreach ( (array)$paged_groups as $group ) $group_ids[] = $group-&gt;id;
+                        $group_ids = $wpdb-&gt;escape( join( ',', (array)$group_ids ) );
+                        $paged_groups = BP_Groups_Group::get_group_extras( &amp;$paged_groups, $group_ids, 'newest' );
+                }
</ins><span class="cx"> 
</span><span class="cx">                 return array( 'groups' =&gt; $paged_groups, 'total' =&gt; $total_groups );
</span><span class="cx">         }
</span><span class="lines">@@ -371,9 +377,11 @@
</span><span class="cx">                         $total_groups = $wpdb-&gt;get_var( &quot;SELECT COUNT(DISTINCT g.id) FROM {$bp-&gt;groups-&gt;table_name_groupmeta} gm1, {$bp-&gt;groups-&gt;table_name_groupmeta} gm2, {$bp-&gt;groups-&gt;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' {$hidden_sql} {$search_sql}&quot; );
</span><span class="cx">                 }
</span><span class="cx"> 
</span><del>-                foreach ( (array)$paged_groups as $group ) $group_ids[] = $group-&gt;id;
-                $group_ids = $wpdb-&gt;escape( join( ',', (array)$group_ids ) );
-                $paged_groups = BP_Groups_Group::get_group_extras( &amp;$paged_groups, $group_ids, 'alphabetical' );
</del><ins>+                if ( empty( $user_id ) ) {
+                        foreach ( (array)$paged_groups as $group ) $group_ids[] = $group-&gt;id;
+                        $group_ids = $wpdb-&gt;escape( join( ',', (array)$group_ids ) );
+                        $paged_groups = BP_Groups_Group::get_group_extras( &amp;$paged_groups, $group_ids, 'newest' );
+                }
</ins><span class="cx"> 
</span><span class="cx">                 return array( 'groups' =&gt; $paged_groups, 'total' =&gt; $total_groups );
</span><span class="cx">         }
</span><span class="lines">@@ -405,9 +413,11 @@
</span><span class="cx">                         $total_groups = $wpdb-&gt;get_var( &quot;SELECT COUNT(DISTINCT g.id) FROM {$bp-&gt;groups-&gt;table_name_groupmeta} gm1, {$bp-&gt;groups-&gt;table_name_groupmeta} gm2, {$bp-&gt;groups-&gt;table_name_groupmeta} gm3, {$bbdb-&gt;forums} f, {$bp-&gt;groups-&gt;table_name} g WHERE g.id = gm1.group_id AND g.id = gm2.group_id AND g.id = gm3.group_id AND gm2.meta_key = 'last_activity' AND gm1.meta_key = 'total_member_count' AND (gm3.meta_key = 'forum_id' AND gm3.meta_value = f.forum_id) AND f.topics &gt; 0 {$hidden_sql} {$search_sql}&quot; );
</span><span class="cx">                 }
</span><span class="cx"> 
</span><del>-                foreach ( (array)$paged_groups as $group ) $group_ids[] = $group-&gt;id;
-                $group_ids = $wpdb-&gt;escape( join( ',', (array)$group_ids ) );
-                $paged_groups = BP_Groups_Group::get_group_extras( &amp;$paged_groups, $group_ids, 'most_forum_topics' );
</del><ins>+                if ( empty( $user_id ) ) {
+                        foreach ( (array)$paged_groups as $group ) $group_ids[] = $group-&gt;id;
+                        $group_ids = $wpdb-&gt;escape( join( ',', (array)$group_ids ) );
+                        $paged_groups = BP_Groups_Group::get_group_extras( &amp;$paged_groups, $group_ids, 'newest' );
+                }
</ins><span class="cx"> 
</span><span class="cx">                 return array( 'groups' =&gt; $paged_groups, 'total' =&gt; $total_groups );
</span><span class="cx">         }
</span><span class="lines">@@ -439,9 +449,11 @@
</span><span class="cx">                         $total_groups = $wpdb-&gt;get_var( &quot;SELECT COUNT(DISTINCT g.id) FROM {$bp-&gt;groups-&gt;table_name_groupmeta} gm1, {$bp-&gt;groups-&gt;table_name_groupmeta} gm2, {$bp-&gt;groups-&gt;table_name_groupmeta} gm3, {$bbdb-&gt;forums} f, {$bp-&gt;groups-&gt;table_name} g WHERE g.id = gm1.group_id AND g.id = gm2.group_id AND g.id = gm3.group_id AND gm2.meta_key = 'last_activity' AND gm1.meta_key = 'total_member_count' AND (gm3.meta_key = 'forum_id' AND gm3.meta_value = f.forum_id) {$hidden_sql} {$search_sql}&quot; );
</span><span class="cx">                 }
</span><span class="cx"> 
</span><del>-                foreach ( (array)$paged_groups as $group ) $group_ids[] = $group-&gt;id;
-                $group_ids = $wpdb-&gt;escape( join( ',', (array)$group_ids ) );
-                $paged_groups = BP_Groups_Group::get_group_extras( &amp;$paged_groups, $group_ids, 'most_forum_posts' );
</del><ins>+                if ( empty( $user_id ) ) {
+                        foreach ( (array)$paged_groups as $group ) $group_ids[] = $group-&gt;id;
+                        $group_ids = $wpdb-&gt;escape( join( ',', (array)$group_ids ) );
+                        $paged_groups = BP_Groups_Group::get_group_extras( &amp;$paged_groups, $group_ids, 'newest' );
+                }
</ins><span class="cx"> 
</span><span class="cx">                 return array( 'groups' =&gt; $paged_groups, 'total' =&gt; $total_groups );
</span><span class="cx">         }
</span><span class="lines">@@ -508,9 +520,11 @@
</span><span class="cx"> 
</span><span class="cx">                 $paged_groups = $wpdb-&gt;get_results( $wpdb-&gt;prepare( &quot;SELECT g.*, gm1.meta_value as total_member_count, gm2.meta_value as last_activity FROM {$bp-&gt;groups-&gt;table_name_groupmeta} gm1, {$bp-&gt;groups-&gt;table_name_groupmeta} gm2, {$bp-&gt;groups-&gt;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}&quot;  ) );
</span><span class="cx"> 
</span><del>-                foreach ( (array)$paged_groups as $group ) $group_ids[] = $group-&gt;id;
-                $group_ids = $wpdb-&gt;escape( join( ',', (array)$group_ids ) );
-                $paged_groups = BP_Groups_Group::get_group_extras( &amp;$paged_groups, $group_ids, 'letter' );
</del><ins>+                if ( empty( $user_id ) ) {
+                        foreach ( (array)$paged_groups as $group ) $group_ids[] = $group-&gt;id;
+                        $group_ids = $wpdb-&gt;escape( join( ',', (array)$group_ids ) );
+                        $paged_groups = BP_Groups_Group::get_group_extras( &amp;$paged_groups, $group_ids, 'newest' );
+                }
</ins><span class="cx"> 
</span><span class="cx">                 return array( 'groups' =&gt; $paged_groups, 'total' =&gt; $total_groups );
</span><span class="cx">         }
</span><span class="lines">@@ -538,9 +552,11 @@
</span><span class="cx">                         $total_groups = $wpdb-&gt;get_var( &quot;SELECT COUNT(DISTINCT g.id) FROM {$bp-&gt;groups-&gt;table_name_groupmeta} gm INNER JOIN {$bp-&gt;groups-&gt;table_name} g ON gm.group_id = g.id WHERE gm.meta_key = 'last_activity'{$hidden_sql} {$search_sql}&quot; );
</span><span class="cx">                 }
</span><span class="cx"> 
</span><del>-                foreach ( (array)$paged_groups as $group ) $group_ids[] = $group-&gt;id;
-                $group_ids = $wpdb-&gt;escape( join( ',', (array)$group_ids ) );
-                $paged_groups = BP_Groups_Group::get_group_extras( &amp;$paged_groups, $group_ids, 'random' );
</del><ins>+                if ( empty( $user_id ) ) {
+                        foreach ( (array)$paged_groups as $group ) $group_ids[] = $group-&gt;id;
+                        $group_ids = $wpdb-&gt;escape( join( ',', (array)$group_ids ) );
+                        $paged_groups = BP_Groups_Group::get_group_extras( &amp;$paged_groups, $group_ids, 'newest' );
+                }
</ins><span class="cx"> 
</span><span class="cx">                 return array( 'groups' =&gt; $paged_groups, 'total' =&gt; $total_groups );
</span><span class="cx">         }
</span></span></pre>
</div>
</div>

</body>
</html>