<!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][13146] trunk: Add a new param to `bp_activity_get()` to only get the number of items</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 { white-space: pre-line; 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" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="http://buddypress.trac.wordpress.org/changeset/13146">13146</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"http://buddypress.trac.wordpress.org/changeset/13146","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>imath</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2021-11-13 15:16:36 +0000 (Sat, 13 Nov 2021)</dd>
</dl>

<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>Add a new param to `bp_activity_get()` to only get the number of items

Using the `count_total_only` parameter with `bp_activity_get()` will only run the query to count the number of activity items. Using this new parameter into the Activity WP Admin Screen improves the performance of the query to get the total number of activities.

Props oztaser

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

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcbpactivitybpactivityfunctionsphp">trunk/src/bp-activity/bp-activity-functions.php</a></li>
<li><a href="#trunksrcbpactivityclassesclassbpactivityactivityphp">trunk/src/bp-activity/classes/class-bp-activity-activity.php</a></li>
<li><a href="#trunksrcbpactivityclassesclassbpactivitylisttablephp">trunk/src/bp-activity/classes/class-bp-activity-list-table.php</a></li>
<li><a href="#trunktestsphpunittestcasesactivityfunctionsphp">trunk/tests/phpunit/testcases/activity/functions.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcbpactivitybpactivityfunctionsphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/bp-activity/bp-activity-functions.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/bp-activity/bp-activity-functions.php   2021-11-13 14:33:37 UTC (rev 13145)
+++ trunk/src/bp-activity/bp-activity-functions.php     2021-11-13 15:16:36 UTC (rev 13146)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1783,7 +1783,6 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        'per_page'          => false,        // results per page.
</span><span class="cx" style="display: block; padding: 0 10px">                        'sort'              => 'DESC',       // sort ASC or DESC.
</span><span class="cx" style="display: block; padding: 0 10px">                        'display_comments'  => false,        // False for no comments. 'stream' for within stream display, 'threaded' for below each activity item.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
</del><span class="cx" style="display: block; padding: 0 10px">                         'search_terms'      => false,        // Pass search terms as a string.
</span><span class="cx" style="display: block; padding: 0 10px">                        'meta_query'        => false,        // Filter by activity meta. See WP_Meta_Query for format.
</span><span class="cx" style="display: block; padding: 0 10px">                        'date_query'        => false,        // Filter by date. See first parameter of WP_Date_Query for format.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1790,11 +1789,11 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        'filter_query'      => false,
</span><span class="cx" style="display: block; padding: 0 10px">                        'show_hidden'       => false,        // Show activity items that are hidden site-wide?
</span><span class="cx" style="display: block; padding: 0 10px">                        'exclude'           => false,        // Comma-separated list of activity IDs to exclude.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        'in'                => false,        // Comma-separated list or array of activity IDs to which you.
-                                                                                               // want to limit the query.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 'in'                => false,        // Comma-separated list or array of activity IDs to which you want to limit the query.
</ins><span class="cx" style="display: block; padding: 0 10px">                         'spam'              => 'ham_only',   // 'ham_only' (default), 'spam_only' or 'all'.
</span><span class="cx" style="display: block; padding: 0 10px">                        'update_meta_cache' => true,
</span><span class="cx" style="display: block; padding: 0 10px">                        'count_total'       => false,
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                        'count_total_only'  => false,
</ins><span class="cx" style="display: block; padding: 0 10px">                         'scope'             => false,
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                        /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1812,26 +1811,29 @@
</span><span class="cx" style="display: block; padding: 0 10px">                'activity_get'
</span><span class="cx" style="display: block; padding: 0 10px">        );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        $activity = BP_Activity_Activity::get( array(
-               'page'              => $r['page'],
-               'per_page'          => $r['per_page'],
-               'max'               => $r['max'],
-               'sort'              => $r['sort'],
-               'search_terms'      => $r['search_terms'],
-               'meta_query'        => $r['meta_query'],
-               'date_query'        => $r['date_query'],
-               'filter_query'      => $r['filter_query'],
-               'filter'            => $r['filter'],
-               'scope'             => $r['scope'],
-               'display_comments'  => $r['display_comments'],
-               'show_hidden'       => $r['show_hidden'],
-               'exclude'           => $r['exclude'],
-               'in'                => $r['in'],
-               'spam'              => $r['spam'],
-               'update_meta_cache' => $r['update_meta_cache'],
-               'count_total'       => $r['count_total'],
-               'fields'            => $r['fields'],
-       ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $activity = BP_Activity_Activity::get(
+               array(
+                       'page'              => $r['page'],
+                       'per_page'          => $r['per_page'],
+                       'max'               => $r['max'],
+                       'sort'              => $r['sort'],
+                       'search_terms'      => $r['search_terms'],
+                       'meta_query'        => $r['meta_query'],
+                       'date_query'        => $r['date_query'],
+                       'filter_query'      => $r['filter_query'],
+                       'filter'            => $r['filter'],
+                       'scope'             => $r['scope'],
+                       'display_comments'  => $r['display_comments'],
+                       'show_hidden'       => $r['show_hidden'],
+                       'exclude'           => $r['exclude'],
+                       'in'                => $r['in'],
+                       'spam'              => $r['spam'],
+                       'update_meta_cache' => $r['update_meta_cache'],
+                       'count_total'       => $r['count_total'],
+                       'count_total_only'  => $r['count_total_only'],
+                       'fields'            => $r['fields'],
+               )
+       );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><span class="cx" style="display: block; padding: 0 10px">         * Filters the requested activity item(s).
</span></span></pre></div>
<a id="trunksrcbpactivityclassesclassbpactivityactivityphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/bp-activity/classes/class-bp-activity-activity.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/bp-activity/classes/class-bp-activity-activity.php      2021-11-13 14:33:37 UTC (rev 13145)
+++ trunk/src/bp-activity/classes/class-bp-activity-activity.php        2021-11-13 15:16:36 UTC (rev 13146)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -341,6 +341,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">         * @since 1.2.0
</span><span class="cx" style="display: block; padding: 0 10px">         * @since 2.4.0 Introduced the `$fields` parameter.
</span><span class="cx" style="display: block; padding: 0 10px">         * @since 2.9.0 Introduced the `$order_by` parameter.
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         * @since 10.0.0 Introduced the `$count_total_only` parameter.
</ins><span class="cx" style="display: block; padding: 0 10px">          *
</span><span class="cx" style="display: block; padding: 0 10px">         * @see BP_Activity_Activity::get_filter_sql() for a description of the
</span><span class="cx" style="display: block; padding: 0 10px">         *      'filter' parameter.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -372,6 +373,8 @@
</span><span class="cx" style="display: block; padding: 0 10px">         *     @type bool         $update_meta_cache Whether to pre-fetch metadata for queried activity items. Default: true.
</span><span class="cx" style="display: block; padding: 0 10px">         *     @type string|bool  $count_total       If true, an additional DB query is run to count the total activity items
</span><span class="cx" style="display: block; padding: 0 10px">         *                                           for the query. Default: false.
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         *     @type bool         $count_total_only  If true, only the DB query to count the total activity items is run.
+        *                                           Default: false.
</ins><span class="cx" style="display: block; padding: 0 10px">          * }
</span><span class="cx" style="display: block; padding: 0 10px">         * @return array The array returned has two keys:
</span><span class="cx" style="display: block; padding: 0 10px">         *               - 'total' is the count of located activities
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -435,6 +438,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                'spam'              => 'ham_only',      // Spam status.
</span><span class="cx" style="display: block; padding: 0 10px">                                'update_meta_cache' => true,            // Whether or not to update meta cache.
</span><span class="cx" style="display: block; padding: 0 10px">                                'count_total'       => false,           // Whether or not to use count_total.
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                'count_total_only'  => false,           // Whether to only get the total count.
</ins><span class="cx" style="display: block; padding: 0 10px">                         )
</span><span class="cx" style="display: block; padding: 0 10px">                );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -629,6 +633,10 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        'has_more_items' => null,
</span><span class="cx" style="display: block; padding: 0 10px">                );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                // Init the activity list.
+               $activities     = array();
+               $only_get_count = (bool) $r['count_total_only'];
+
</ins><span class="cx" style="display: block; padding: 0 10px">                 /**
</span><span class="cx" style="display: block; padding: 0 10px">                 * Filters if BuddyPress should use legacy query structure over current structure for version 2.0+.
</span><span class="cx" style="display: block; padding: 0 10px">                 *
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -640,7 +648,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                 * @param BP_Activity_Activity $value Current method being called.
</span><span class="cx" style="display: block; padding: 0 10px">                 * @param array                $r     Parsed arguments passed into method.
</span><span class="cx" style="display: block; padding: 0 10px">                 */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                if ( apply_filters( 'bp_use_legacy_activity_query', false, __METHOD__, $r ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( ! $only_get_count && apply_filters( 'bp_use_legacy_activity_query', false, __METHOD__, $r ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                        // Legacy queries joined against the user table.
</span><span class="cx" style="display: block; padding: 0 10px">                        $select_sql = "SELECT DISTINCT a.*, u.user_email, u.user_nicename, u.user_login, u.display_name";
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -692,7 +700,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                $activities[ $i ]->is_spam           = (int) $ac->is_spam;
</span><span class="cx" style="display: block; padding: 0 10px">                        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                } else {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         } elseif ( ! $only_get_count ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                         // Query first for activity IDs.
</span><span class="cx" style="display: block; padding: 0 10px">                        $activity_ids_sql = "{$select_sql} {$from_sql} {$join_sql} {$where_sql} ORDER BY {$order_by} {$sort}, a.id {$sort}";
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -745,7 +753,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        }
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                if ( 'ids' !== $r['fields'] ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( $activities && 'ids' !== $r['fields'] ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                         // Get the fullnames of users so we don't have to query in the loop.
</span><span class="cx" style="display: block; padding: 0 10px">                        $activities = self::append_user_fullnames( $activities );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -772,9 +780,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $retval['activities'] = $activities;
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                // If $max is set, only return up to the max results.
-               if ( ! empty( $r['count_total'] ) ) {
-
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         // Only query the count total if requested.
+               if ( ! empty( $r['count_total'] ) || $only_get_count ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                         /**
</span><span class="cx" style="display: block; padding: 0 10px">                         * Filters the total activities MySQL statement.
</span><span class="cx" style="display: block; padding: 0 10px">                         *
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -785,6 +792,17 @@
</span><span class="cx" style="display: block; padding: 0 10px">                         * @param string $sort      Sort direction for query.
</span><span class="cx" style="display: block; padding: 0 10px">                         */
</span><span class="cx" style="display: block; padding: 0 10px">                        $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 );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+                       /*
+                        * Queries that include 'last_activity' are cached separately,
+                        * since they are generally much less long-lived.
+                        */
+                       if ( preg_match( '/a\.type NOT IN \([^\)]*\'last_activity\'[^\)]*\)/', $total_activities_sql ) ) {
+                               $cache_group = 'bp_activity';
+                       } else {
+                               $cache_group = 'bp_activity_with_last_activity';
+                       }
+
</ins><span class="cx" style="display: block; padding: 0 10px">                         $cached = bp_core_get_incremented_cache( $total_activities_sql, $cache_group );
</span><span class="cx" style="display: block; padding: 0 10px">                        if ( false === $cached ) {
</span><span class="cx" style="display: block; padding: 0 10px">                                $total_activities = $wpdb->get_var( $total_activities_sql );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -793,7 +811,8 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                $total_activities = $cached;
</span><span class="cx" style="display: block; padding: 0 10px">                        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        if ( !empty( $r['max'] ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 // If $max is set, only return up to the max results.
+                       if ( ! empty( $r['max'] ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                                 if ( (int) $total_activities > (int) $r['max'] ) {
</span><span class="cx" style="display: block; padding: 0 10px">                                        $total_activities = $r['max'];
</span><span class="cx" style="display: block; padding: 0 10px">                                }
</span></span></pre></div>
<a id="trunksrcbpactivityclassesclassbpactivitylisttablephp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/bp-activity/classes/class-bp-activity-list-table.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/bp-activity/classes/class-bp-activity-list-table.php    2021-11-13 14:33:37 UTC (rev 13145)
+++ trunk/src/bp-activity/classes/class-bp-activity-list-table.php      2021-11-13 15:16:36 UTC (rev 13146)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -156,7 +156,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        'display_comments' => 'stream',
</span><span class="cx" style="display: block; padding: 0 10px">                        'show_hidden'      => true,
</span><span class="cx" style="display: block; padding: 0 10px">                        'spam'             => 'spam_only',
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        'count_total'      => 'count_query',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 'count_total_only' => true,
</ins><span class="cx" style="display: block; padding: 0 10px">                 ) );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->spam_count = $spams['total'];
</span><span class="cx" style="display: block; padding: 0 10px">                unset( $spams );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -214,9 +214,9 @@
</span><span class="cx" style="display: block; padding: 0 10px">                } elseif ( 'single' !== $this->view ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        $count_activities = bp_activity_get(
</span><span class="cx" style="display: block; padding: 0 10px">                                array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                        'fields'      => 'ids',
-                                       'show_hidden' => true,
-                                       'count_total' => 'count_query',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                 'fields'           => 'ids',
+                                       'show_hidden'      => true,
+                                       'count_total_only' => true,
</ins><span class="cx" style="display: block; padding: 0 10px">                                 )
</span><span class="cx" style="display: block; padding: 0 10px">                        );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span></span></pre></div>
<a id="trunktestsphpunittestcasesactivityfunctionsphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/testcases/activity/functions.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/testcases/activity/functions.php      2021-11-13 14:33:37 UTC (rev 13145)
+++ trunk/tests/phpunit/testcases/activity/functions.php        2021-11-13 15:16:36 UTC (rev 13146)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1974,4 +1974,29 @@
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertEqualSets( [ $a1 ], bp_activity_get_user_favorites( $u1 ) );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertSame( $latest_update, bp_get_user_meta( $u1, 'bp_latest_update', true ) );
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+       /**
+        * @ticket BP8591
+        */
+       public function test_activity_admin_screen_count_activities() {
+               $u1 = self::factory()->user->create();
+               $a1 = self::factory()->activity->create_many(
+                       5,
+                       array(
+                               'user_id'   => $u1,
+                               'component' => 'activity',
+                               'type'      => 'activity_update',
+                       )
+               );
+               bp_update_user_last_activity( $u1, date( 'Y-m-d H:i:s', bp_core_current_time( true, 'timestamp' ) ) );
+
+               $count_activities = bp_activity_get(
+                       array(
+                               'show_hidden'      => true,
+                               'count_total_only' => true,
+                       )
+               );
+
+               $this->assertTrue( 5 === (int) $count_activities['total'] );
+       }
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre>
</div>
</div>

</body>
</html>