<!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] [2533] trunk:
Removing database hits inside BP loops to improve overall performance.</title>
</head>
<body>
<div id="msg">
<dl>
<dt>Revision</dt> <dd>2533</dd>
<dt>Author</dt> <dd>apeatling</dd>
<dt>Date</dt> <dd>2010-02-02 12:40:49 +0000 (Tue, 02 Feb 2010)</dd>
</dl>
<h3>Log Message</h3>
<pre>Removing database hits inside BP loops to improve overall performance.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkbpcorebpcoreclassesphp">trunk/bp-core/bp-core-classes.php</a></li>
<li><a href="#trunkbpcorebpcoretemplatetagsphp">trunk/bp-core/bp-core-templatetags.php</a></li>
<li><a href="#trunkbpforumsbpforumstemplatetagsphp">trunk/bp-forums/bp-forums-templatetags.php</a></li>
<li><a href="#trunkbpforumsphp">trunk/bp-forums.php</a></li>
<li><a href="#trunkbpfriendsbpfriendstemplatetagsphp">trunk/bp-friends/bp-friends-templatetags.php</a></li>
<li><a href="#trunkbpgroupsbpgroupsclassesphp">trunk/bp-groups/bp-groups-classes.php</a></li>
<li><a href="#trunkbpgroupsbpgroupstemplatetagsphp">trunk/bp-groups/bp-groups-templatetags.php</a></li>
<li><a href="#trunkbpthemesbpdefault_incglobaljs">trunk/bp-themes/bp-default/_inc/global.js</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkbpcorebpcoreclassesphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-core/bp-core-classes.php (2532 => 2533)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-core/bp-core-classes.php        2010-02-02 08:33:39 UTC (rev 2532)
+++ trunk/bp-core/bp-core-classes.php        2010-02-02 12:40:49 UTC (rev 2533)
</span><span class="lines">@@ -339,6 +339,27 @@
</span><span class="cx">                         }
</span><span class="cx">                 }
</span><span class="cx">
</span><ins>+                /* Fetch whether or not the user is a friend */
+                if ( function_exists( 'friends_install' ) ) {
+                        $friend_status = $wpdb->get_results( $wpdb->prepare( "SELECT initiator_user_id, friend_user_id, is_confirmed FROM {$bp->friends->table_name} WHERE (initiator_user_id = %d AND friend_user_id IN ( {$user_ids} ) ) OR (initiator_user_id IN ( {$user_ids} ) AND friend_user_id = %d )", $bp->loggedin_user->id, $bp->loggedin_user->id ) );
+                        for ( $i = 0; $i < count( $paged_users ); $i++ ) {
+                                foreach ( $friend_status as $status ) {
+                                        if ( $status->initiator_user_id == $paged_users[$i]->id || $status->friend_user_id == $paged_users[$i]->id )
+                                                $paged_users[$i]->is_friend = $status->is_confirmed;
+                                }
+                        }
+                }
+
+                if ( 'active' != $type ) {
+                        $user_activity = $wpdb->get_results( "SELECT user_id as id, meta_value as last_activity FROM " . CUSTOM_USER_META_TABLE . " WHERE meta_key = 'last_activity' AND user_id IN ( {$user_ids} )" );
+                        for ( $i = 0; $i < count( $paged_users ); $i++ ) {
+                                foreach ( $user_activity as $activity ) {
+                                        if ( $activity->id == $paged_users[$i]->id )
+                                                $paged_users[$i]->last_activity = $activity->last_activity;
+                                }
+                        }
+                }
+
</ins><span class="cx">                 /* Fetch the user's last_activity */
</span><span class="cx">                 if ( 'active' != $type ) {
</span><span class="cx">                         $user_activity = $wpdb->get_results( "SELECT user_id as id, meta_value as last_activity FROM " . CUSTOM_USER_META_TABLE . " WHERE meta_key = 'last_activity' AND user_id IN ( {$user_ids} )" );
</span></span></pre></div>
<a id="trunkbpcorebpcoretemplatetagsphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-core/bp-core-templatetags.php (2532 => 2533)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-core/bp-core-templatetags.php        2010-02-02 08:33:39 UTC (rev 2532)
+++ trunk/bp-core/bp-core-templatetags.php        2010-02-02 12:40:49 UTC (rev 2533)
</span><span class="lines">@@ -341,7 +341,12 @@
</span><span class="cx">         global $members_template;
</span><span class="cx">
</span><span class="cx">         if ( function_exists( 'bp_add_friend_button' ) ) {
</span><del>-                echo bp_add_friend_button( $members_template->member->id );
</del><ins>+                if ( null === $members_template->member->is_friend )
+                        $friend_status = 'not_friends';
+                else
+                        $friend_status = ( 0 == $members_template->member->is_friend ) ? 'pending' : 'is_friend';
+
+                echo bp_add_friend_button( $members_template->member->id, $friend_status );
</ins><span class="cx">         }
</span><span class="cx"> }
</span><span class="cx">
</span></span></pre></div>
<a id="trunkbpforumsbpforumstemplatetagsphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-forums/bp-forums-templatetags.php (2532 => 2533)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-forums/bp-forums-templatetags.php        2010-02-02 08:33:39 UTC (rev 2532)
+++ trunk/bp-forums/bp-forums-templatetags.php        2010-02-02 12:40:49 UTC (rev 2533)
</span><span class="lines">@@ -92,6 +92,9 @@
</span><span class="cx">                         $this->topics = array_merge( (array)$stickies, (array)$standard );
</span><span class="cx">                 }
</span><span class="cx">
</span><ins>+                /* Fetch extra information for topics, so we don't have to query inside the loop */
+                $this->topics = bp_forums_get_topic_extras( &$this->topics );
+
</ins><span class="cx">                 $this->pag_links = paginate_links( array(
</span><span class="cx">                         'base' => add_query_arg( array( 'p' => '%#%', 'n' => $this->pag_num ) ),
</span><span class="cx">                         'format' => '',
</span><span class="lines">@@ -347,10 +350,10 @@
</span><span class="cx">         function bp_get_the_topic_last_poster_name() {
</span><span class="cx">                 global $forum_template;
</span><span class="cx">
</span><del>-                if ( !$name = bp_core_get_userlink( $forum_template->topic->topic_last_poster ) )
</del><ins>+                if ( !$domain = bp_core_get_user_domain( $forum_template->topic->topic_last_poster, $forum_template->topic->topic_last_poster_nicename, $forum_template->topic->topic_last_poster_login ) )
</ins><span class="cx">                         return __( 'Deleted User', 'buddypress' );
</span><span class="cx">
</span><del>-                return apply_filters( 'bp_get_the_topic_last_poster_name', $name );
</del><ins>+                return apply_filters( 'bp_get_the_topic_last_poster_name', '<a href="' . $domain . '">' . $forum_template->topic->topic_last_poster_displayname . '</a>' );
</ins><span class="cx">         }
</span><span class="cx">
</span><span class="cx"> function bp_the_topic_object_avatar( $args = '' ) {
</span><span class="lines">@@ -386,7 +389,7 @@
</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_get_the_topic_last_poster_avatar', bp_core_fetch_avatar( array( 'item_id' => $forum_template->topic->topic_last_poster, 'type' => $type, 'width' => $width, 'height' => $height ) ) );
</del><ins>+                return apply_filters( 'bp_get_the_topic_last_poster_avatar', bp_core_fetch_avatar( array( 'email' => $forum_template->topic->topic_last_poster_email, 'item_id' => $forum_template->topic->topic_last_poster, 'type' => $type, 'width' => $width, 'height' => $height ) ) );
</ins><span class="cx">         }
</span><span class="cx">
</span><span class="cx"> function bp_the_topic_start_time() {
</span></span></pre></div>
<a id="trunkbpforumsphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-forums.php (2532 => 2533)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-forums.php        2010-02-02 08:33:39 UTC (rev 2532)
+++ trunk/bp-forums.php        2010-02-02 12:40:49 UTC (rev 2533)
</span><span class="lines">@@ -333,6 +333,43 @@
</span><span class="cx">         return $count;
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+function bp_forums_get_topic_extras( $topics ) {
+        global $bp, $wpdb, $bbdb;
+
+        if ( empty( $topics ) )
+                return $topics;
+
+        /* Get the topic ids */
+        foreach ( $topics as $topic ) $topic_ids[] = $topic->topic_id;
+        $topic_ids = $wpdb->escape( join( ',', (array)$topic_ids ) );
+
+        /* Fetch the topic's last poster details */
+        $poster_details = $wpdb->get_results( $wpdb->prepare( "SELECT t.topic_id, t.topic_last_poster, u.user_login, u.user_nicename, u.user_email, u.display_name FROM {$wpdb->users} u, {$bbdb->topics} t WHERE u.ID = t.topic_last_poster AND t.topic_id IN ( {$topic_ids} )" ) );
+        for ( $i = 0; $i < count( $topics ); $i++ ) {
+                foreach ( $poster_details as $poster ) {
+                        if ( $poster->topic_id == $topics[$i]->topic_id ) {
+                                $topics[$i]->topic_last_poster_email = $poster->user_email;
+                                $topics[$i]->topic_last_poster_nicename = $poster->user_nicename;
+                                $topics[$i]->topic_last_poster_login = $poster->user_login;
+                                $topics[$i]->topic_last_poster_displayname = $poster->display_name;
+                        }
+                }
+        }
+
+        /* Fetch fullname for the topic's last poster */
+        if ( function_exists( 'xprofile_install' ) ) {
+                $poster_names = $wpdb->get_results( $wpdb->prepare( "SELECT t.topic_id, pd.value FROM {$bp->profile->table_name_data} pd, {$bbdb->topics} t WHERE pd.user_id = t.topic_last_poster AND pd.field_id = 1 AND t.topic_id IN ( {$topic_ids} )" ) );
+                for ( $i = 0; $i < count( $topics ); $i++ ) {
+                        foreach ( $poster_names as $name ) {
+                                if ( $name->topic_id == $topics[$i]->topic_id )
+                                        $topics[$i]->topic_last_poster_displayname = $name->value;
+                        }
+                }
+        }
+
+        return $topics;
+}
+
</ins><span class="cx"> /* Post Functions */
</span><span class="cx">
</span><span class="cx"> function bp_forums_get_topic_posts( $args = '' ) {
</span></span></pre></div>
<a id="trunkbpfriendsbpfriendstemplatetagsphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-friends/bp-friends-templatetags.php (2532 => 2533)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-friends/bp-friends-templatetags.php        2010-02-02 08:33:39 UTC (rev 2532)
+++ trunk/bp-friends/bp-friends-templatetags.php        2010-02-02 12:40:49 UTC (rev 2533)
</span><span class="lines">@@ -114,10 +114,10 @@
</span><span class="cx">         <?php
</span><span class="cx"> }
</span><span class="cx">
</span><del>-function bp_add_friend_button( $potential_friend_id = false ) {
-        echo bp_get_add_friend_button( $potential_friend_id );
</del><ins>+function bp_add_friend_button( $potential_friend_id = false, $friend_status = false ) {
+        echo bp_get_add_friend_button( $potential_friend_id, $friend_status );
</ins><span class="cx"> }
</span><del>-        function bp_get_add_friend_button( $potential_friend_id = false ) {
</del><ins>+        function bp_get_add_friend_button( $potential_friend_id = false, $friend_status = false ) {
</ins><span class="cx">                 global $bp, $friends_template;
</span><span class="cx">
</span><span class="cx">                 if ( !is_user_logged_in() )
</span><span class="lines">@@ -131,7 +131,8 @@
</span><span class="cx">                 if ( $bp->loggedin_user->id == $potential_friend_id )
</span><span class="cx">                         return false;
</span><span class="cx">
</span><del>-                $friend_status = friends_check_friendship_status( $bp->loggedin_user->id, $potential_friend_id );
</del><ins>+                if ( empty( $friend_status ) )
+                        $friend_status = friends_check_friendship_status( $bp->loggedin_user->id, $potential_friend_id );
</ins><span class="cx">
</span><span class="cx">                 $button = '<div class="generic-button friendship-button ' . $friend_status . '" id="friendship-button-' . $potential_friend_id . '">';
</span><span class="cx">                 if ( 'pending' == $friend_status ) {
</span></span></pre></div>
<a id="trunkbpgroupsbpgroupsclassesphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-groups/bp-groups-classes.php (2532 => 2533)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-groups/bp-groups-classes.php        2010-02-02 08:33:39 UTC (rev 2532)
+++ trunk/bp-groups/bp-groups-classes.php        2010-02-02 12:40:49 UTC (rev 2533)
</span><span class="lines">@@ -47,11 +47,12 @@
</span><span class="cx">                         if ( $get_user_dataset ) {
</span><span class="cx">                                 $this->user_dataset = $this->get_user_dataset();
</span><span class="cx">
</span><del>-                                //if ( !$this->total_member_count ) {
</del><span class="cx">                                 $this->total_member_count = count( $this->user_dataset );
</span><span class="cx">                                 groups_update_groupmeta( $this->id, 'total_member_count', $this->total_member_count );
</span><del>-                                //}
</del><span class="cx">                         }
</span><ins>+
+                        /* Get group extras */
+                        $this->is_member = BP_Groups_Member::check_is_member( $bp->loggedin_user->id, $this->id );
</ins><span class="cx">                 }
</span><span class="cx">         }
</span><span class="cx">
</span><span class="lines">@@ -335,6 +336,9 @@
</span><span class="cx">                         $total_groups = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(DISTINCT g.id) FROM {$bp->groups->table_name_groupmeta} gm INNER JOIN {$bp->groups->table_name} g ON gm.group_id = g.id WHERE gm.meta_key = 'last_activity'{$hidden_sql} {$search_sql}" ) );
</span><span class="cx">                 }
</span><span class="cx">
</span><ins>+                $group_ids = $wpdb->escape( join( ',', (array)$group_ids ) );
+                $paged_groups = BP_Groups_Group::get_group_extras( &$paged_groups, $group_ids, 'newest' );
+
</ins><span class="cx">                 return array( 'groups' => $paged_groups, 'total' => $total_groups );
</span><span class="cx">         }
</span><span class="cx">
</span><span class="lines">@@ -360,6 +364,10 @@
</span><span class="cx">                         $total_groups = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(DISTINCT g.id) FROM {$bp->groups->table_name_groupmeta} gm INNER JOIN {$bp->groups->table_name} g ON gm.group_id = g.id WHERE gm.meta_key = 'last_activity'{$hidden_sql} {$search_sql}" ) );
</span><span class="cx">                 }
</span><span class="cx">
</span><ins>+                foreach ( $paged_groups as $group ) $group_ids[] = $group->id;
+                $group_ids = $wpdb->escape( join( ',', (array)$group_ids ) );
+                $paged_groups = BP_Groups_Group::get_group_extras( &$paged_groups, $group_ids, 'active' );
+
</ins><span class="cx">                 return array( 'groups' => $paged_groups, 'total' => $total_groups );
</span><span class="cx">         }
</span><span class="cx">
</span><span class="lines">@@ -386,6 +394,9 @@
</span><span class="cx">                         $total_groups = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(DISTINCT g.id) 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' {$hidden_sql} {$search_sql}" ) );
</span><span class="cx">                 }
</span><span class="cx">
</span><ins>+                $group_ids = $wpdb->escape( join( ',', (array)$group_ids ) );
+                $paged_groups = BP_Groups_Group::get_group_extras( &$paged_groups, $group_ids, 'popular' );
+
</ins><span class="cx">                 return array( 'groups' => $paged_groups, 'total' => $total_groups );
</span><span class="cx">         }
</span><span class="cx">
</span><span class="lines">@@ -411,6 +422,9 @@
</span><span class="cx">                         $total_groups = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(DISTINCT g.id) 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' {$hidden_sql} {$search_sql}" ) );
</span><span class="cx">                 }
</span><span class="cx">
</span><ins>+                $group_ids = $wpdb->escape( join( ',', (array)$group_ids ) );
+                $paged_groups = BP_Groups_Group::get_group_extras( &$paged_groups, $group_ids, 'alphabetical' );
+
</ins><span class="cx">                 return array( 'groups' => $paged_groups, 'total' => $total_groups );
</span><span class="cx">         }
</span><span class="cx">
</span><span class="lines">@@ -440,6 +454,9 @@
</span><span class="cx">                         $total_groups = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(DISTINCT g.id) FROM {$bp->groups->table_name_groupmeta} gm1, {$bp->groups->table_name_groupmeta} gm2, {$bp->groups->table_name_groupmeta} gm3, {$bbdb->forums} f, {$bp->groups->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 > 0 {$hidden_sql} {$search_sql}" ) );
</span><span class="cx">                 }
</span><span class="cx">
</span><ins>+                $group_ids = $wpdb->escape( join( ',', (array)$group_ids ) );
+                $paged_groups = BP_Groups_Group::get_group_extras( &$paged_groups, $group_ids, 'most_forum_topics' );
+
</ins><span class="cx">                 return array( 'groups' => $paged_groups, 'total' => $total_groups );
</span><span class="cx">         }
</span><span class="cx">
</span><span class="lines">@@ -469,6 +486,9 @@
</span><span class="cx">                         $total_groups = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(DISTINCT g.id) FROM {$bp->groups->table_name_groupmeta} gm1, {$bp->groups->table_name_groupmeta} gm2, {$bp->groups->table_name_groupmeta} gm3, {$bbdb->forums} f, {$bp->groups->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}" ) );
</span><span class="cx">                 }
</span><span class="cx">
</span><ins>+                $group_ids = $wpdb->escape( join( ',', (array)$group_ids ) );
+                $paged_groups = BP_Groups_Group::get_group_extras( &$paged_groups, $group_ids, 'most_forum_posts' );
+
</ins><span class="cx">                 return array( 'groups' => $paged_groups, 'total' => $total_groups );
</span><span class="cx">         }
</span><span class="cx">
</span><span class="lines">@@ -534,6 +554,9 @@
</span><span class="cx">
</span><span class="cx">                 $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}" ) );
</span><span class="cx">
</span><ins>+                $group_ids = $wpdb->escape( join( ',', (array)$group_ids ) );
+                $paged_groups = BP_Groups_Group::get_group_extras( &$paged_groups, $group_ids, 'letter' );
+
</ins><span class="cx">                 return array( 'groups' => $paged_groups, 'total' => $total_groups );
</span><span class="cx">         }
</span><span class="cx">
</span><span class="lines">@@ -559,9 +582,38 @@
</span><span class="cx">                         $total_groups = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(DISTINCT g.id) FROM {$bp->groups->table_name_groupmeta} gm INNER JOIN {$bp->groups->table_name} g ON gm.group_id = g.id WHERE gm.meta_key = 'last_activity'{$hidden_sql} {$search_sql}" ) );
</span><span class="cx">                 }
</span><span class="cx">
</span><ins>+                $group_ids = $wpdb->escape( join( ',', (array)$group_ids ) );
+                $paged_groups = BP_Groups_Group::get_group_extras( &$paged_groups, $group_ids, 'random' );
+
</ins><span class="cx">                 return array( 'groups' => $paged_groups, 'total' => $total_groups );
</span><span class="cx">         }
</span><span class="cx">
</span><ins>+        function get_group_extras( $paged_groups, $group_ids, $type = false ) {
+                global $bp, $wpdb;
+
+                if ( empty( $group_ids ) )
+                        return $paged_groups;
+
+                /* Fetch the logged in users status within each group */
+                $user_status = $wpdb->get_col( $wpdb->prepare( "SELECT group_id FROM {$bp->groups->table_name_members} WHERE user_id = %d AND group_id IN ( {$group_ids} ) AND is_confirmed = 1 AND is_banned = 0", $bp->loggedin_user->id ) );
+                for ( $i = 0; $i < count( $paged_groups ); $i++ ) {
+                        foreach ( $user_status as $group_id ) {
+                                if ( $group_id == $paged_groups[$i]->id )
+                                        $paged_groups[$i]->is_member = true;
+                        }
+                }
+
+                $user_banned = $wpdb->get_col( $wpdb->prepare( "SELECT group_id FROM {$bp->groups->table_name_members} WHERE is_banned = 1 AND user_id = %d AND group_id IN ( {$group_ids} )", $bp->loggedin_user->id ) );
+                for ( $i = 0; $i < count( $paged_groups ); $i++ ) {
+                        foreach ( $user_banned as $group_id ) {
+                                if ( $group_id == $paged_groups[$i]->id )
+                                        $paged_groups[$i]->is_banned = true;
+                        }
+                }
+
+                return $paged_groups;
+        }
+
</ins><span class="cx">         function delete_all_invites( $group_id ) {
</span><span class="cx">                 global $wpdb, $bp;
</span><span class="cx">
</span></span></pre></div>
<a id="trunkbpgroupsbpgroupstemplatetagsphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-groups/bp-groups-templatetags.php (2532 => 2533)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-groups/bp-groups-templatetags.php        2010-02-02 08:33:39 UTC (rev 2532)
+++ trunk/bp-groups/bp-groups-templatetags.php        2010-02-02 12:40:49 UTC (rev 2533)
</span><span class="lines">@@ -1079,10 +1079,10 @@
</span><span class="cx">         if ( !$group )
</span><span class="cx">                 $group =& $groups_template->group;
</span><span class="cx">
</span><del>-        if ( groups_is_user_member( $bp->loggedin_user->id, $group->id ) )
-                return true;
</del><ins>+        if ( null == $group->is_member )
+                return false;
</ins><span class="cx">
</span><del>-        return false;
</del><ins>+        return true;
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> function bp_group_accept_invite_link( $deprecated = false ) {
</span><span class="lines">@@ -1167,7 +1167,7 @@
</span><span class="cx">                 $group =& $groups_template->group;
</span><span class="cx">
</span><span class="cx">         // If they're not logged in or are banned from the group, no join button.
</span><del>-        if ( !is_user_logged_in() || groups_is_user_banned( $bp->loggedin_user->id, $group->id ) )
</del><ins>+        if ( !is_user_logged_in() || $group->is_banned )
</ins><span class="cx">                 return false;
</span><span class="cx">
</span><span class="cx">         if ( !$group->status )
</span><span class="lines">@@ -1177,14 +1177,14 @@
</span><span class="cx">
</span><span class="cx">         switch ( $group->status ) {
</span><span class="cx">                 case 'public':
</span><del>-                        if ( BP_Groups_Member::check_is_member( $bp->loggedin_user->id, $group->id ) )
</del><ins>+                        if ( $group->is_member )
</ins><span class="cx">                                 echo '<a class="leave-group" href="' . wp_nonce_url( bp_get_group_permalink( $group ) . 'leave-group', 'groups_leave_group' ) . '">' . __( 'Leave Group', 'buddypress' ) . '</a>';
</span><span class="cx">                         else
</span><span class="cx">                                 echo '<a class="join-group" href="' . wp_nonce_url( bp_get_group_permalink( $group ) . 'join', 'groups_join_group' ) . '">' . __( 'Join Group', 'buddypress' ) . '</a>';
</span><span class="cx">                 break;
</span><span class="cx">
</span><span class="cx">                 case 'private':
</span><del>-                        if ( BP_Groups_Member::check_is_member( $bp->loggedin_user->id, $group->id ) ) {
</del><ins>+                        if ( $group->is_member ) {
</ins><span class="cx">                                 echo '<a class="leave-group" href="' . wp_nonce_url( bp_get_group_permalink( $group ) . 'leave-group', 'groups_leave_group' ) . '">' . __( 'Leave Group', 'buddypress' ) . '</a>';
</span><span class="cx">                         } else {
</span><span class="cx">                                 if ( !bp_group_has_requested_membership( $group ) )
</span></span></pre></div>
<a id="trunkbpthemesbpdefault_incglobaljs"></a>
<div class="modfile"><h4>Modified: trunk/bp-themes/bp-default/_inc/global.js (2532 => 2533)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-themes/bp-default/_inc/global.js        2010-02-02 08:33:39 UTC (rev 2532)
+++ trunk/bp-themes/bp-default/_inc/global.js        2010-02-02 12:40:49 UTC (rev 2533)
</span><span class="lines">@@ -796,12 +796,7 @@
</span><span class="cx">
</span><span class="cx">         /** Alternate Highlighting ******************************************/
</span><span class="cx">
</span><del>-        j('table tr').each( function(i) {
-                if ( i % 2 == 1 )
-                        j(this).addClass('alt');
-        });
-
-        j('div.message-box, ul#topic-post-list li').each( function(i) {
</del><ins>+        j('table tr, div.message-box, ul#topic-post-list li').each( function(i) {
</ins><span class="cx">                 if ( i % 2 != 1 )
</span><span class="cx">                         j(this).addClass('alt');
</span><span class="cx">         });
</span></span></pre>
</div>
</div>
</body>
</html>