<!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" />
<title>[BuddyPress][8491] trunk: Disable COUNT queries by default in bp_activity_get() stack</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { 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 #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#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>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://buddypress.trac.wordpress.org/changeset/8491">8491</a></dd>
<dt>Author</dt> <dd>boonebgorges</dd>
<dt>Date</dt> <dd>2014-06-09 18:33:05 +0000 (Mon, 09 Jun 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Disable COUNT queries by default in bp_activity_get() stack

The COUNT query performed to get the total activity count has proven to be a
performance bottleneck on large sites. Moreover, the way that activity items
are displayed on the front end (using the Load More link) means that the total
count is not actually used by BuddyPress in most cases. To reduce query
overhead, we introduce a 'count_total' parameter to the bp_activity_get()
stack, and set it to false by default.

For backward compatibility, a few additional changes are introduced:

- In the activity-loop.php template, the <noscript> pagination markup is
  removed. In its place, the Load More link is refactored so that it loads
  the next available page of activity items.
- The mechanism used to determine whether there are more activity items to show
  (bp_activity_has_more_items()) has been refined; when no COUNT query takes
  place, we query for the $per_page value + 1 to infer whether more items are
  available.

Fixes <a href="http://buddypress.trac.wordpress.org/ticket/5629">#5629</a>

Props boonebgorges, r-a-y</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcbpactivitybpactivityadminphp">trunk/src/bp-activity/bp-activity-admin.php</a></li>
<li><a href="#trunksrcbpactivitybpactivityclassesphp">trunk/src/bp-activity/bp-activity-classes.php</a></li>
<li><a href="#trunksrcbpactivitybpactivityfunctionsphp">trunk/src/bp-activity/bp-activity-functions.php</a></li>
<li><a href="#trunksrcbpactivitybpactivitytemplatephp">trunk/src/bp-activity/bp-activity-template.php</a></li>
<li><a href="#trunksrcbptemplatesbplegacybuddypressactivityactivityloopphp">trunk/src/bp-templates/bp-legacy/buddypress/activity/activity-loop.php</a></li>
<li><a href="#trunktestsphpunittestcasesactivityclassBP_Activity_Activityphp">trunk/tests/phpunit/testcases/activity/class.BP_Activity_Activity.php</a></li>
<li><a href="#trunktestsphpunittestcasesactivitytemplatephp">trunk/tests/phpunit/testcases/activity/template.php</a></li>
<li><a href="#trunktestsphpunittestcasesblogsfunctionsphp">trunk/tests/phpunit/testcases/blogs/functions.php</a></li>
<li><a href="#trunktestsphpunittestcasesxprofileactivityphp">trunk/tests/phpunit/testcases/xprofile/activity.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcbpactivitybpactivityadminphp"></a>
<div class="modfile"><h4>Modified: trunk/src/bp-activity/bp-activity-admin.php (8490 => 8491)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/bp-activity/bp-activity-admin.php      2014-06-09 15:12:49 UTC (rev 8490)
+++ trunk/src/bp-activity/bp-activity-admin.php 2014-06-09 18:33:05 UTC (rev 8491)
</span><span class="lines">@@ -1057,6 +1057,7 @@
</span><span class="cx">                  'display_comments' => 'stream',
</span><span class="cx">                  'show_hidden'      => true,
</span><span class="cx">                  'spam'             => 'spam_only',
</span><ins>+                       'count_total'      => 'count_query',
</ins><span class="cx">           ) );
</span><span class="cx">          $this->spam_count = $spams['total'];
</span><span class="cx">          unset( $spams );
</span><span class="lines">@@ -1072,6 +1073,7 @@
</span><span class="cx">                  'show_hidden'      => true,
</span><span class="cx">                  //'sort'             => $sort,
</span><span class="cx">                  'spam'             => $spam,
</span><ins>+                       'count_total'      => 'count_query',
</ins><span class="cx">           ) );
</span><span class="cx"> 
</span><span class="cx">          // If we're viewing a specific activity, flatten all activites into a single array.
</span></span></pre></div>
<a id="trunksrcbpactivitybpactivityclassesphp"></a>
<div class="modfile"><h4>Modified: trunk/src/bp-activity/bp-activity-classes.php (8490 => 8491)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/bp-activity/bp-activity-classes.php    2014-06-09 15:12:49 UTC (rev 8490)
+++ trunk/src/bp-activity/bp-activity-classes.php       2014-06-09 18:33:05 UTC (rev 8491)
</span><span class="lines">@@ -267,6 +267,9 @@
</span><span class="cx">   *     @type string $spam Spam status. Default: 'ham_only'.
</span><span class="cx">   *     @type bool $update_meta_cache Whether to pre-fetch metadata for
</span><span class="cx">   *           queried activity items. Default: true.
</span><ins>+        *     @type string|bool $count_total If true, an additional DB query
+        *           is run to count the total activity items for the query.
+        *           Default: false.
</ins><span class="cx">    * }
</span><span class="cx">   * @return array The array returned has two keys:
</span><span class="cx">   *     - 'total' is the count of located activities
</span><span class="lines">@@ -311,6 +314,7 @@
</span><span class="cx">                  'show_hidden'       => false,      // Show items marked hide_sitewide
</span><span class="cx">                  'spam'              => 'ham_only', // Spam status
</span><span class="cx">                  'update_meta_cache' => true,
</span><ins>+                       'count_total'       => false,
</ins><span class="cx">           );
</span><span class="cx">          $r = wp_parse_args( $args, $defaults );
</span><span class="cx">          extract( $r );
</span><span class="lines">@@ -411,6 +415,12 @@
</span><span class="cx">          $page     = absint( $page     );
</span><span class="cx">          $per_page = absint( $per_page );
</span><span class="cx"> 
</span><ins>+               $retval = array(
+                       'activities'     => null,
+                       'total'          => null,
+                       'has_more_items' => null,
+               );
+
</ins><span class="cx">           // Filter and return true to use the legacy query structure (not recommended)
</span><span class="cx">          if ( apply_filters( 'bp_use_legacy_activity_query', false, __METHOD__, $r ) ) {
</span><span class="cx"> 
</span><span class="lines">@@ -431,18 +441,26 @@
</span><span class="cx">                  $activity_ids_sql = "{$select_sql} {$from_sql} {$join_sql} {$where_sql} ORDER BY a.date_recorded {$sort}";
</span><span class="cx"> 
</span><span class="cx">                  if ( ! empty( $per_page ) && ! empty( $page ) ) {
</span><del>-                               $activity_ids_sql .= $wpdb->prepare( " LIMIT %d, %d", absint( ( $page - 1 ) * $per_page ), $per_page );
</del><ins>+                                // We query for $per_page + 1 items in order to
+                               // populate the has_more_items flag
+                               $activity_ids_sql .= $wpdb->prepare( " LIMIT %d, %d", absint( ( $page - 1 ) * $per_page ), $per_page + 1 );
</ins><span class="cx">                   }
</span><span class="cx"> 
</span><span class="cx">                  $activity_ids_sql = apply_filters( 'bp_activity_paged_activities_sql', $activity_ids_sql, $r );
</span><span class="cx"> 
</span><span class="cx">                  $activity_ids = $wpdb->get_col( $activity_ids_sql );
</span><del>-                       $activities   = self::get_activity_data( $activity_ids );
</del><ins>+
+                       $retval['has_more_items'] = ! empty( $per_page ) && count( $activity_ids ) > $per_page;
+
+                       // If we've fetched more than the $per_page value, we
+                       // can discard the extra now
+                       if ( ! empty( $per_page ) && count( $activity_ids ) === $per_page + 1 ) {
+                               array_pop( $activity_ids );
+                       }
+
+                       $activities = self::get_activity_data( $activity_ids );
</ins><span class="cx">           }
</span><span class="cx"> 
</span><del>-               $total_activities_sql = apply_filters( 'bp_activity_total_activities_sql', "SELECT count(DISTINCT a.id) FROM {$bp->activity->table_name} a {$join_sql} {$where_sql}", $where_sql, $sort );
-               $total_activities     = $wpdb->get_var( $total_activities_sql );
-
</del><span class="cx">           // Get the fullnames of users so we don't have to query in the loop
</span><span class="cx">          $activities = self::append_user_fullnames( $activities );
</span><span class="cx"> 
</span><span class="lines">@@ -465,13 +483,23 @@
</span><span class="cx">          // Generate action strings
</span><span class="cx">          $activities = BP_Activity_Activity::generate_action_strings( $activities );
</span><span class="cx"> 
</span><ins>+               $retval['activities'] = $activities;
+
</ins><span class="cx">           // If $max is set, only return up to the max results
</span><del>-               if ( !empty( $max ) ) {
-                       if ( (int) $total_activities > (int) $max )
-                               $total_activities = $max;
</del><ins>+                if ( ! empty( $r['count_total'] ) ) {
+
+                       $total_activities_sql = apply_filters( 'bp_activity_total_activities_sql', "SELECT count(DISTINCT a.id) FROM {$bp->activity->table_name} a {$join_sql} {$where_sql}", $where_sql, $sort );
+                       $total_activities     = $wpdb->get_var( $total_activities_sql );
+
+                       if ( !empty( $max ) ) {
+                               if ( (int) $total_activities > (int) $max )
+                                       $total_activities = $max;
+                       }
+
+                       $retval['total'] = $total_activities;
</ins><span class="cx">           }
</span><span class="cx"> 
</span><del>-               return array( 'activities' => $activities, 'total' => (int) $total_activities );
</del><ins>+                return $retval;
</ins><span class="cx">   }
</span><span class="cx"> 
</span><span class="cx">  /**
</span></span></pre></div>
<a id="trunksrcbpactivitybpactivityfunctionsphp"></a>
<div class="modfile"><h4>Modified: trunk/src/bp-activity/bp-activity-functions.php (8490 => 8491)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/bp-activity/bp-activity-functions.php  2014-06-09 15:12:49 UTC (rev 8490)
+++ trunk/src/bp-activity/bp-activity-functions.php     2014-06-09 18:33:05 UTC (rev 8491)
</span><span class="lines">@@ -963,6 +963,7 @@
</span><span class="cx">          'in'                => false,        // Comma-separated list or array of activity IDs to which you want to limit the query
</span><span class="cx">          'spam'              => 'ham_only',   // 'ham_only' (default), 'spam_only' or 'all'.
</span><span class="cx">          'update_meta_cache' => true,
</span><ins>+               'count_total'       => false,
</ins><span class="cx"> 
</span><span class="cx">          /**
</span><span class="cx">           * Pass filters as an array -- all filter items can be multiple values comma separated:
</span><span class="lines">@@ -994,6 +995,7 @@
</span><span class="cx">                          'show_hidden'       => $show_hidden,
</span><span class="cx">                          'spam'              => $spam,
</span><span class="cx">                          'update_meta_cache' => $update_meta_cache,
</span><ins>+                               'count_total'       => $count_total,
</ins><span class="cx">                   );
</span><span class="cx">                  $activity = BP_Activity_Activity::get( $args );
</span><span class="cx">                  wp_cache_set( 'bp_activity_sitewide_front', $activity, 'bp' );
</span><span class="lines">@@ -1012,7 +1014,8 @@
</span><span class="cx">                  'show_hidden'      => $show_hidden,
</span><span class="cx">                  'exclude'          => $exclude,
</span><span class="cx">                  'in'               => $in,
</span><del>-                       'spam'             => $spam
</del><ins>+                        'spam'             => $spam,
+                       'count_total'      => $count_total,
</ins><span class="cx">           );
</span><span class="cx">          $activity = BP_Activity_Activity::get( $args );
</span><span class="cx">  }
</span></span></pre></div>
<a id="trunksrcbpactivitybpactivitytemplatephp"></a>
<div class="modfile"><h4>Modified: trunk/src/bp-activity/bp-activity-template.php (8490 => 8491)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/bp-activity/bp-activity-template.php   2014-06-09 15:12:49 UTC (rev 8490)
+++ trunk/src/bp-activity/bp-activity-template.php      2014-06-09 18:33:05 UTC (rev 8491)
</span><span class="lines">@@ -98,6 +98,14 @@
</span><span class="cx"> 
</span><span class="cx">  var $in_the_loop;
</span><span class="cx"> 
</span><ins>+       /**
+        * URL parameter key for activity pagination. Default: 'acpage'.
+        *
+        * @since BuddyPress (2.1.0)
+        * @var string
+        */
+       var $pag_arg;
+
</ins><span class="cx">   var $pag_page;
</span><span class="cx">  var $pag_num;
</span><span class="cx">  var $pag_links;
</span><span class="lines">@@ -178,7 +186,8 @@
</span><span class="cx">          $r = wp_parse_args( $args, $defaults );
</span><span class="cx">          extract( $r );
</span><span class="cx"> 
</span><del>-               $this->pag_page = isset( $_REQUEST[$page_arg] ) ? intval( $_REQUEST[$page_arg] ) : $page;
</del><ins>+                $this->pag_arg  = $r['page_arg'];
+               $this->pag_page = isset( $_REQUEST[ $this->pag_arg ] ) ? intval( $_REQUEST[ $this->pag_arg ] ) : $page;
</ins><span class="cx">           $this->pag_num  = isset( $_REQUEST['num'] ) ? intval( $_REQUEST['num'] ) : $per_page;
</span><span class="cx"> 
</span><span class="cx">          // Check if blog/forum replies are disabled
</span><span class="lines">@@ -220,11 +229,18 @@
</span><span class="cx">                  ) );
</span><span class="cx">          }
</span><span class="cx"> 
</span><del>-               if ( !$max || $max >= (int) $this->activities['total'] )
-                       $this->total_activity_count = (int) $this->activities['total'];
-               else
-                       $this->total_activity_count = (int) $max;
</del><ins>+                // The total_activity_count property will be set only if a
+               // 'count_total' query has taken place
+               if ( ! is_null( $this->activities['total'] ) ) {
+                       if ( ! $max || $max >= (int) $this->activities['total'] ) {
+                               $this->total_activity_count = (int) $this->activities['total'];
+                       } else {
+                               $this->total_activity_count = (int) $max;
+                       }
+               }
</ins><span class="cx"> 
</span><ins>+               $this->has_more_items = $this->activities['has_more_items'];
+
</ins><span class="cx">           $this->activities = $this->activities['activities'];
</span><span class="cx"> 
</span><span class="cx">          if ( $max ) {
</span><span class="lines">@@ -706,6 +722,23 @@
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> /**
</span><ins>+ * Output the URL for the Load More link.
+ *
+ * @since BuddyPress (2.1.0)
+ */
+function bp_activity_load_more_link() {
+       echo bp_get_activity_load_more_link();
+}
+       function bp_get_activity_load_more_link() {
+               global $activities_template;
+
+               $link = bp_get_requested_url();
+               $link = add_query_arg( $activities_template->pag_arg, $activities_template->pag_page + 1, $link );
+
+               return apply_filters( 'bp_get_activity_load_more_link', $link );
+       }
+
+/**
</ins><span class="cx">  * Output the activity pagination count.
</span><span class="cx">  *
</span><span class="cx">  * @since BuddyPress (1.0)
</span><span class="lines">@@ -778,14 +811,18 @@
</span><span class="cx"> function bp_activity_has_more_items() {
</span><span class="cx">  global $activities_template;
</span><span class="cx"> 
</span><del>-       $remaining_pages = 0;
</del><ins>+        if ( ! empty( $activities_template->has_more_items )  ) {
+               $has_more_items = true;
+       } else {
+               $remaining_pages = 0;
</ins><span class="cx"> 
</span><del>-       if ( ! empty( $activities_template->pag_page ) ) {
-               $remaining_pages = floor( ( $activities_template->total_activity_count - 1 ) / ( $activities_template->pag_num * $activities_template->pag_page ) );
</del><ins>+                if ( ! empty( $activities_template->pag_page ) ) {
+                       $remaining_pages = floor( ( $activities_template->total_activity_count - 1 ) / ( $activities_template->pag_num * $activities_template->pag_page ) );
+               }
+
+               $has_more_items = (int) $remaining_pages > 0;
</ins><span class="cx">   }
</span><span class="cx"> 
</span><del>-       $has_more_items  = (int) $remaining_pages ? true : false;
-
</del><span class="cx">   return apply_filters( 'bp_activity_has_more_items', $has_more_items );
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunksrcbptemplatesbplegacybuddypressactivityactivityloopphp"></a>
<div class="modfile"><h4>Modified: trunk/src/bp-templates/bp-legacy/buddypress/activity/activity-loop.php (8490 => 8491)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/bp-templates/bp-legacy/buddypress/activity/activity-loop.php   2014-06-09 15:12:49 UTC (rev 8490)
+++ trunk/src/bp-templates/bp-legacy/buddypress/activity/activity-loop.php      2014-06-09 18:33:05 UTC (rev 8491)
</span><span class="lines">@@ -2,14 +2,6 @@
</span><span class="cx"> 
</span><span class="cx"> <?php if ( bp_has_activities( bp_ajax_querystring( 'activity' ) ) ) : ?>
</span><span class="cx"> 
</span><del>-       <?php /* Show pagination if JS is not enabled, since the "Load More" link will do nothing */ ?>
-       <noscript>
-               <div class="pagination">
-                       <div class="pag-count"><?php bp_activity_pagination_count(); ?></div>
-                       <div class="pagination-links"><?php bp_activity_pagination_links(); ?></div>
-               </div>
-       </noscript>
-
</del><span class="cx">   <?php if ( empty( $_POST['page'] ) ) : ?>
</span><span class="cx"> 
</span><span class="cx">          <ul id="activity-stream" class="activity-list item-list">
</span><span class="lines">@@ -25,7 +17,7 @@
</span><span class="cx">  <?php if ( bp_activity_has_more_items() ) : ?>
</span><span class="cx"> 
</span><span class="cx">          <li class="load-more">
</span><del>-                       <a href="#more"><?php _e( 'Load More', 'buddypress' ); ?></a>
</del><ins>+                        <a href="<?php bp_activity_load_more_link() ?>"><?php _e( 'Load More', 'buddypress' ); ?></a>
</ins><span class="cx">           </li>
</span><span class="cx"> 
</span><span class="cx">  <?php endif; ?>
</span></span></pre></div>
<a id="trunktestsphpunittestcasesactivityclassBP_Activity_Activityphp"></a>
<div class="modfile"><h4>Modified: trunk/tests/phpunit/testcases/activity/class.BP_Activity_Activity.php (8490 => 8491)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/tests/phpunit/testcases/activity/class.BP_Activity_Activity.php    2014-06-09 15:12:49 UTC (rev 8490)
+++ trunk/tests/phpunit/testcases/activity/class.BP_Activity_Activity.php       2014-06-09 18:33:05 UTC (rev 8491)
</span><span class="lines">@@ -135,6 +135,7 @@
</span><span class="cx">                                  'value' => 'barry',
</span><span class="cx">                          ),
</span><span class="cx">                  ),
</span><ins>+                       'count_total' => 'count_query',
</ins><span class="cx">           ) );
</span><span class="cx"> 
</span><span class="cx">          $ids = wp_list_pluck( $activity['activities'], 'id' );
</span><span class="lines">@@ -311,6 +312,49 @@
</span><span class="cx">  }
</span><span class="cx"> 
</span><span class="cx">  /**
</span><ins>+        * @group get
+        * @group count_total
+        */
+       public function test_get_with_count_total() {
+               $a1 = $this->factory->activity->create();
+               $a2 = $this->factory->activity->create();
+
+               $activity = BP_Activity_Activity::get( array(
+                       'count_total' => 'count_query',
+               ) );
+
+               $this->assertEquals( 2, $activity['total'] );
+       }
+
+       /**
+        * @group get
+        * @group count_total
+        */
+       public function test_get_with_count_total_false() {
+               $a1 = $this->factory->activity->create();
+               $a2 = $this->factory->activity->create();
+
+               $activity = BP_Activity_Activity::get( array(
+                       'count_total' => false,
+               ) );
+
+               $this->assertSame( null, $activity['total'] );
+       }
+
+       /**
+        * @group get
+        * @group count_total
+        */
+       public function test_get_with_count_total_default_to_false() {
+               $a1 = $this->factory->activity->create();
+               $a2 = $this->factory->activity->create();
+
+               $activity = BP_Activity_Activity::get();
+
+               $this->assertSame( null, $activity['total'] );
+       }
+
+       /**
</ins><span class="cx">    * @group get_id
</span><span class="cx">   */
</span><span class="cx">  public function test_get_id_with_item_id() {
</span></span></pre></div>
<a id="trunktestsphpunittestcasesactivitytemplatephp"></a>
<div class="modfile"><h4>Modified: trunk/tests/phpunit/testcases/activity/template.php (8490 => 8491)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/tests/phpunit/testcases/activity/template.php      2014-06-09 15:12:49 UTC (rev 8490)
+++ trunk/tests/phpunit/testcases/activity/template.php 2014-06-09 18:33:05 UTC (rev 8491)
</span><span class="lines">@@ -375,4 +375,84 @@
</span><span class="cx">          update_option( 'thread_comments_depth', $tcd );
</span><span class="cx">          $activities_template = null;
</span><span class="cx">  }
</span><ins>+
+       /**
+        * @group bp_activity_has_more_items
+        */
+       public function test_bp_activity_has_more_items_no_count_total_false() {
+               $a1 = $this->factory->activity->create();
+               $a2 = $this->factory->activity->create();
+
+               $args = array(
+                       'count_total' => false,
+               );
+
+               if ( bp_has_activities( $args ) ) {
+                       global $activities_template;
+                       $this->assertFalse( bp_activity_has_more_items() );
+                       $activities_template = null;
+               }
+       }
+
+       /**
+        * @group bp_activity_has_more_items
+        */
+       public function test_bp_activity_has_more_items_no_count_total_true() {
+               $a1 = $this->factory->activity->create();
+               $a2 = $this->factory->activity->create();
+               $a3 = $this->factory->activity->create();
+               $a4 = $this->factory->activity->create();
+
+               $args = array(
+                       'count_total' => false,
+                       'per_page' => 2,
+               );
+
+               if ( bp_has_activities( $args ) ) {
+                       global $activities_template;
+                       $this->assertTrue( bp_activity_has_more_items() );
+                       $activities_template = null;
+               }
+       }
+
+       /**
+        * @group bp_activity_has_more_items
+        */
+       public function test_bp_activity_has_more_items_count_total_false() {
+               $a1 = $this->factory->activity->create();
+               $a2 = $this->factory->activity->create();
+               $a3 = $this->factory->activity->create();
+               $a4 = $this->factory->activity->create();
+
+               $args = array(
+                       'count_total' => 'count_query',
+               );
+
+               if ( bp_has_activities( $args ) ) {
+                       global $activities_template;
+                       $this->assertFalse( bp_activity_has_more_items() );
+                       $activities_template = null;
+               }
+       }
+
+       /**
+        * @group bp_activity_has_more_items
+        */
+       public function test_bp_activity_has_more_items_count_total_true() {
+               $a1 = $this->factory->activity->create();
+               $a2 = $this->factory->activity->create();
+               $a3 = $this->factory->activity->create();
+               $a4 = $this->factory->activity->create();
+
+               $args = array(
+                       'count_total' => 'count_query',
+                       'per_page' => 2,
+               );
+
+               if ( bp_has_activities( $args ) ) {
+                       global $activities_template;
+                       $this->assertTrue( bp_activity_has_more_items() );
+                       $activities_template = null;
+               }
+       }
</ins><span class="cx"> }
</span></span></pre></div>
<a id="trunktestsphpunittestcasesblogsfunctionsphp"></a>
<div class="modfile"><h4>Modified: trunk/tests/phpunit/testcases/blogs/functions.php (8490 => 8491)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/tests/phpunit/testcases/blogs/functions.php        2014-06-09 15:12:49 UTC (rev 8490)
+++ trunk/tests/phpunit/testcases/blogs/functions.php   2014-06-09 18:33:05 UTC (rev 8491)
</span><span class="lines">@@ -402,6 +402,6 @@
</span><span class="cx">                  'secondary_item_id' => $post_id,
</span><span class="cx">          ) );
</span><span class="cx"> 
</span><del>-               return ! empty( $a['total'] );
</del><ins>+                return ! empty( $a['activities'] );
</ins><span class="cx">   }
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunktestsphpunittestcasesxprofileactivityphp"></a>
<div class="modfile"><h4>Modified: trunk/tests/phpunit/testcases/xprofile/activity.php (8490 => 8491)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/tests/phpunit/testcases/xprofile/activity.php      2014-06-09 15:12:49 UTC (rev 8490)
+++ trunk/tests/phpunit/testcases/xprofile/activity.php 2014-06-09 18:33:05 UTC (rev 8491)
</span><span class="lines">@@ -104,6 +104,7 @@
</span><span class="cx">                          'object' => buddypress()->profile->id,
</span><span class="cx">                          'action' => 'updated_profile',
</span><span class="cx">                  ),
</span><ins>+                       'count_total' => 'count_query',
</ins><span class="cx">           ) );
</span><span class="cx"> 
</span><span class="cx">          $this->assertEquals( 1, $existing['total'] );
</span><span class="lines">@@ -138,6 +139,7 @@
</span><span class="cx">                          'object' => buddypress()->profile->id,
</span><span class="cx">                          'action' => 'updated_profile',
</span><span class="cx">                  ),
</span><ins>+                       'count_total' => 'count_query',
</ins><span class="cx">           ) );
</span><span class="cx"> 
</span><span class="cx">          $this->assertEquals( 1, $existing['total'] );
</span></span></pre>
</div>
</div>

</body>
</html>