<!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][13989] trunk: Members: Add `cache_results` flag to the `BP_Signup::get` getter.</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/13989">13989</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/13989","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>espellcaste</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2024-07-27 20:12:32 +0000 (Sat, 27 Jul 2024)</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'>Members: Add `cache_results` flag to the `BP_Signup::get` getter.

When performing a request with `cache_results`, it stops the signup information retrieved from being added to the cache.

See <a href="http://buddypress.trac.wordpress.org/ticket/8552">#8552</a>
Closes https://github.com/buddypress/buddypress/pull/345/</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcbpmembersclassesclassbpsignupphp">trunk/src/bp-members/classes/class-bp-signup.php</a></li>
<li><a href="#trunktestsphpunittestcasesmembersclassbpsignupphp">trunk/tests/phpunit/testcases/members/class-bp-signup.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcbpmembersclassesclassbpsignupphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/bp-members/classes/class-bp-signup.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/bp-members/classes/class-bp-signup.php  2024-07-27 19:58:27 UTC (rev 13988)
+++ trunk/src/bp-members/classes/class-bp-signup.php    2024-07-27 20:12:32 UTC (rev 13989)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -258,7 +258,8 @@
</span><span class="cx" style="display: block; padding: 0 10px">         * Fetch signups based on parameters.
</span><span class="cx" style="display: block; padding: 0 10px">         *
</span><span class="cx" style="display: block; padding: 0 10px">         * @since 2.0.0
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-         * @since 6.0.0 Added a list of allowed orderby parameters.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+  * @since 6.0.0  Added a list of allowed orderby parameters.
+        * @since 15.0.0 Introduced the `cache_results` parameter.
</ins><span class="cx" style="display: block; padding: 0 10px">          *
</span><span class="cx" style="display: block; padding: 0 10px">         * @global wpdb $wpdb The WordPress database object.
</span><span class="cx" style="display: block; padding: 0 10px">         *
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -266,15 +267,16 @@
</span><span class="cx" style="display: block; padding: 0 10px">         *     The argument to retrieve desired signups.
</span><span class="cx" style="display: block; padding: 0 10px">         *     @type int         $offset         Offset amount. Default 0.
</span><span class="cx" style="display: block; padding: 0 10px">         *     @type int         $number         How many to fetch. Pass -1 to fetch all. Default 1.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-         *     @type bool|string $usersearch     Whether or not to search for a username. Default false.
-        *     @type string      $orderby        Order By parameter. Possible values are `signup_id`, `login`, `email`,
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+  *     @type bool|string $usersearch     Whether to search for a username. Default false.
+        *     @type string      $orderby        Order by parameter. Possible values are `signup_id`, `login`, `email`,
</ins><span class="cx" style="display: block; padding: 0 10px">          *                                       `registered`, `activated`. Default `signup_id`.
</span><span class="cx" style="display: block; padding: 0 10px">         *     @type string      $order          Order direction. Default 'DESC'.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-         *     @type bool        $include        Whether or not to include more specific query params.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+  *     @type bool        $include        Whether to include more specific query params.
</ins><span class="cx" style="display: block; padding: 0 10px">          *     @type string      $activation_key Activation key to search for. If specified, all other
</span><span class="cx" style="display: block; padding: 0 10px">         *                                       parameters will be ignored.
</span><span class="cx" style="display: block; padding: 0 10px">         *     @type int|bool    $active         Pass 0 for inactive signups, 1 for active signups,
</span><span class="cx" style="display: block; padding: 0 10px">         *                                       and `false` to ignore.
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         *     @type bool        $cache_results  Optional. Whether to cache signup information. Default true.
</ins><span class="cx" style="display: block; padding: 0 10px">          *     @type string      $user_login     Specific user login to return.
</span><span class="cx" style="display: block; padding: 0 10px">         *     @type string      $fields         Which fields to return. Specify 'ids' to fetch a list of signups IDs.
</span><span class="cx" style="display: block; padding: 0 10px">         *                                       Default: 'all' (return BP_Signup objects).
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -301,6 +303,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                'active'         => 0,
</span><span class="cx" style="display: block; padding: 0 10px">                                'user_email'     => '',
</span><span class="cx" style="display: block; padding: 0 10px">                                'user_login'     => '',
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                'cache_results'  => true,
</ins><span class="cx" style="display: block; padding: 0 10px">                                 'fields'         => 'all',
</span><span class="cx" style="display: block; padding: 0 10px">                        ),
</span><span class="cx" style="display: block; padding: 0 10px">                        'bp_core_signups_get_args'
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -318,19 +321,19 @@
</span><span class="cx" style="display: block; padding: 0 10px">                $r['orderby'] = sanitize_title( $r['orderby'] );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $sql = array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        'select'     => "SELECT DISTINCT signup_id",
-                       'from'       => "{$bp->members->table_name_signups}",
-                       'where'      => array(),
-                       'orderby'    => '',
-                       'limit'      => '',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 'select'  => 'SELECT DISTINCT signup_id',
+                       'from'    => "{$bp->members->table_name_signups}",
+                       'where'   => array(),
+                       'orderby' => '',
+                       'limit'   => '',
</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">                // Activation key trumps other parameters because it should be unique.
</span><span class="cx" style="display: block; padding: 0 10px">                if ( ! empty( $r['activation_key'] ) ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        $sql['where'][] = $wpdb->prepare( "activation_key = %s", $r['activation_key'] );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 $sql['where'][] = $wpdb->prepare( 'activation_key = %s', $r['activation_key'] );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                        // `Include` finds signups by ID.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                } else if ( ! empty( $r['include'] ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         } elseif ( ! empty( $r['include'] ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                        $in             = implode( ',', wp_parse_id_list( $r['include'] ) );
</span><span class="cx" style="display: block; padding: 0 10px">                        $sql['where'][] = "signup_id IN ({$in})";
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -342,31 +345,31 @@
</span><span class="cx" style="display: block; padding: 0 10px">                } else {
</span><span class="cx" style="display: block; padding: 0 10px">                        // Active.
</span><span class="cx" style="display: block; padding: 0 10px">                        if ( false !== $r['active'] ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                $sql['where'][] = $wpdb->prepare( "active = %d", absint( $r['active'] ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         $sql['where'][] = $wpdb->prepare( 'active = %d', absint( $r['active'] ) );
</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">                        // Search terms.
</span><span class="cx" style="display: block; padding: 0 10px">                        if ( ! empty( $r['usersearch'] ) ) {
</span><span class="cx" style="display: block; padding: 0 10px">                                $search_terms_like = '%' . bp_esc_like( $r['usersearch'] ) . '%';
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                $sql['where'][]    = $wpdb->prepare( "( user_login LIKE %s OR user_email LIKE %s OR meta LIKE %s )", $search_terms_like, $search_terms_like, $search_terms_like );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         $sql['where'][]    = $wpdb->prepare( '( user_login LIKE %s OR user_email LIKE %s OR meta LIKE %s )', $search_terms_like, $search_terms_like, $search_terms_like );
</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">                        // User email.
</span><span class="cx" style="display: block; padding: 0 10px">                        if ( ! empty( $r['user_email'] ) ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                $sql['where'][] = $wpdb->prepare( "user_email = %s", $r['user_email'] );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         $sql['where'][] = $wpdb->prepare( 'user_email = %s', $r['user_email'] );
</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">                        // User login.
</span><span class="cx" style="display: block; padding: 0 10px">                        if ( ! empty( $r['user_login'] ) ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                $sql['where'][] = $wpdb->prepare( "user_login = %s", $r['user_login'] );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         $sql['where'][] = $wpdb->prepare( 'user_login = %s', $r['user_login'] );
</ins><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">-                        $order          = bp_esc_sql_order( $r['order'] );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 $order          = bp_esc_sql_order( $r['order'] );
</ins><span class="cx" style="display: block; padding: 0 10px">                         $sql['orderby'] = "ORDER BY {$r['orderby']} {$order}";
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                        $number = intval( $r['number'] );
</span><span class="cx" style="display: block; padding: 0 10px">                        if ( -1 !== $number ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                $sql['limit'] = $wpdb->prepare( "LIMIT %d, %d", absint( $r['offset'] ), $number );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         $sql['limit'] = $wpdb->prepare( 'LIMIT %d, %d', absint( $r['offset'] ), $number );
</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">@@ -380,32 +383,37 @@
</span><span class="cx" style="display: block; padding: 0 10px">                 *
</span><span class="cx" style="display: block; padding: 0 10px">                 * @since 2.0.0
</span><span class="cx" style="display: block; padding: 0 10px">                 *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                 * @param string $value SQL statement.
-                * @param array  $sql   Array of SQL statement parts.
-                * @param array  $args  Array of original arguments for get() method.
-                * @param array  $r     Array of parsed arguments for get() method.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+          * @param string $paged_signups_sql SQL statement.
+                * @param array  $sql               Array of SQL statement parts.
+                * @param array  $args              Array of original arguments for get() method.
+                * @param array  $r                 Array of parsed arguments for get() method.
</ins><span class="cx" style="display: block; padding: 0 10px">                  */
</span><span class="cx" style="display: block; padding: 0 10px">                $paged_signups_sql = apply_filters( 'bp_members_signups_paged_query', $paged_signups_sql, $sql, $args, $r );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $cached = bp_core_get_incremented_cache( $paged_signups_sql, 'bp_signups' );
-               if ( false === $cached ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( $r['cache_results'] ) {
+                       $cached = bp_core_get_incremented_cache( $paged_signups_sql, 'bp_signups' );
+                       if ( false === $cached ) {
+                               $paged_signup_ids = $wpdb->get_col( $paged_signups_sql );
+                               bp_core_set_incremented_cache( $paged_signups_sql, 'bp_signups', $paged_signup_ids );
+                       } else {
+                               $paged_signup_ids = $cached;
+                       }
+               } else {
</ins><span class="cx" style="display: block; padding: 0 10px">                         $paged_signup_ids = $wpdb->get_col( $paged_signups_sql );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        bp_core_set_incremented_cache( $paged_signups_sql, 'bp_signups', $paged_signup_ids );
-               } else {
-                       $paged_signup_ids = $cached;
</del><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">                // We only want the IDs.
</span><span class="cx" style="display: block; padding: 0 10px">                if ( 'ids' === $r['fields'] ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        $paged_signups = array_map( 'intval', $paged_signup_ids );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
</del><span class="cx" style="display: block; padding: 0 10px">                 } else {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        $uncached_signup_ids = bp_get_non_cached_ids( $paged_signup_ids, 'bp_signups' );
-                       if ( $uncached_signup_ids ) {
-                               $signup_ids_sql      = implode( ',', array_map( 'intval', $uncached_signup_ids ) );
-                               $signup_data_objects = $wpdb->get_results( "SELECT * FROM {$bp->members->table_name_signups} WHERE signup_id IN ({$signup_ids_sql})" );
-                               foreach ( $signup_data_objects as $signup_data_object ) {
-                                       wp_cache_set( $signup_data_object->signup_id, $signup_data_object, 'bp_signups' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 if ( $r['cache_results'] ) {
+                               $uncached_signup_ids = bp_get_non_cached_ids( $paged_signup_ids, 'bp_signups' );
+                               if ( $uncached_signup_ids ) {
+                                       $signup_ids_sql      = implode( ',', array_map( 'intval', $uncached_signup_ids ) );
+                                       $signup_data_objects = $wpdb->get_results( "SELECT * FROM {$bp->members->table_name_signups} WHERE signup_id IN ({$signup_ids_sql})" );
+                                       foreach ( $signup_data_objects as $signup_data_object ) {
+                                               wp_cache_set( $signup_data_object->signup_id, $signup_data_object, 'bp_signups' );
+                                       }
</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">@@ -419,26 +427,33 @@
</span><span class="cx" style="display: block; padding: 0 10px">                $total_signups_sql = "SELECT COUNT(DISTINCT signup_id) FROM {$sql['from']} {$sql['where']}";
</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">-                 * Filters the Signups count query.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+          * Filters the signups count query.
</ins><span class="cx" style="display: block; padding: 0 10px">                  *
</span><span class="cx" style="display: block; padding: 0 10px">                 * @since 2.0.0
</span><span class="cx" style="display: block; padding: 0 10px">                 *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                 * @param string $value SQL statement.
-                * @param array  $sql   Array of SQL statement parts.
-                * @param array  $args  Array of original arguments for get() method.
-                * @param array  $r     Array of parsed arguments for get() method.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+          * @param string $total_signups_sql SQL statement.
+                * @param array  $sql               Array of SQL statement parts.
+                * @param array  $args              Array of original arguments for get() method.
+                * @param array  $r                 Array of parsed arguments for get() method.
</ins><span class="cx" style="display: block; padding: 0 10px">                  */
</span><span class="cx" style="display: block; padding: 0 10px">                $total_signups_sql = apply_filters( 'bp_members_signups_count_query', $total_signups_sql, $sql, $args, $r );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $cached = bp_core_get_incremented_cache( $total_signups_sql, 'bp_signups' );
-               if ( false === $cached ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( $r['cache_results'] ) {
+                       $cached = bp_core_get_incremented_cache( $total_signups_sql, 'bp_signups' );
+                       if ( false === $cached ) {
+                               $total_signups = (int) $wpdb->get_var( $total_signups_sql );
+                               bp_core_set_incremented_cache( $total_signups_sql, 'bp_signups', $total_signups );
+                       } else {
+                               $total_signups = (int) $cached;
+                       }
+               } else {
</ins><span class="cx" style="display: block; padding: 0 10px">                         $total_signups = (int) $wpdb->get_var( $total_signups_sql );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        bp_core_set_incremented_cache( $total_signups_sql, 'bp_signups', $total_signups );
-               } else {
-                       $total_signups = (int) $cached;
</del><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">-                return array( 'signups' => $paged_signups, 'total' => $total_signups );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         return array(
+                       'signups' => $paged_signups,
+                       'total'   => $total_signups,
+               );
</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="trunktestsphpunittestcasesmembersclassbpsignupphp"></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/members/class-bp-signup.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/testcases/members/class-bp-signup.php 2024-07-27 19:58:27 UTC (rev 13988)
+++ trunk/tests/phpunit/testcases/members/class-bp-signup.php   2024-07-27 20:12:32 UTC (rev 13989)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -358,50 +358,108 @@
</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><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         * @ticket BP8552
</ins><span class="cx" style="display: block; padding: 0 10px">          * @group cache
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        public function test_get_queries_should_be_cached() {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public function test_signup_query_with_ids_cache_results() {
</ins><span class="cx" style="display: block; padding: 0 10px">                 global $wpdb;
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $s = self::factory()->signup->create();
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         self::factory()->signup->create_many( 2 );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $found1 = BP_Signup::get(
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         // Reset.
+               $wpdb->num_queries = 0;
+
+               $first_query = BP_Signup::get(
</ins><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',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         'cache_results' => true,
+                               'fields'        => 'ids',
</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><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $num_queries = $wpdb->num_queries;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $queries_before = get_num_queries();
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $found2 = BP_Signup::get(
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $second_query = BP_Signup::get(
</ins><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',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         'cache_results' => false,
+                               'fields'        => 'ids',
</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><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $this->assertEqualSets( $found1, $found2 );
-               $this->assertSame( $num_queries, $wpdb->num_queries );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $queries_after = get_num_queries();
+
+               $this->assertNotSame( $queries_before, $queries_after, 'Assert that queries are run' );
+               $this->assertSame( 4, $queries_after, 'Assert that the uncached query was run' );
+               $this->assertSameSets( $first_query['signups'], $second_query['signups'], 'Results of the query are expected to match.' );
+               $this->assertSame( $first_query['total'], $second_query['total'], 'Results of the query are expected to match.' );
</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><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         * @ticket BP8552
</ins><span class="cx" style="display: block; padding: 0 10px">          * @group cache
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+        public function test_signup_query_with_all_cache_results() {
+               global $wpdb;
+
+               self::factory()->signup->create_many( 2 );
+
+               // Reset.
+               $wpdb->num_queries = 0;
+
+               $first_query = BP_Signup::get(
+                       array( 'cache_results' => true )
+               );
+
+               $queries_before = get_num_queries();
+
+               $second_query = BP_Signup::get(
+                       array( 'cache_results' => false )
+               );
+
+               $queries_after = get_num_queries();
+
+               $this->assertNotSame( $queries_before, $queries_after, 'Assert that queries are run' );
+               $this->assertSame( 5, $queries_after, 'Assert that the uncached query was run' );
+               $this->assertSame( $first_query['total'], $second_query['total'], 'Results of the query are expected to match.' );
+       }
+
+       /**
+        * @group cache
+        */
+       public function test_get_queries_should_be_cached() {
+               global $wpdb;
+
+               self::factory()->signup->create_many( 2 );
+
+               // Reset.
+               $wpdb->num_queries = 0;
+
+               $args = array( 'fields' => 'ids' );
+
+               $first_query = BP_Signup::get( $args );
+
+               $queries_before = get_num_queries();
+
+               $second_query = BP_Signup::get( $args );
+
+               $queries_after = get_num_queries();
+
+               $this->assertSame( $queries_before, $queries_after, 'Assert that queries are run' );
+               $this->assertSame( 2, $queries_after, 'Assert that the uncached query was run' );
+               $this->assertSameSets( $first_query['signups'], $second_query['signups'], 'Results of the query are expected to match.' );
+       }
+
+       /**
+        * @group cache
+        */
</ins><span class="cx" style="display: block; padding: 0 10px">         public function test_get_query_caches_should_be_busted_by_add() {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $s1 = self::factory()->signup->create();
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $s1   = self::factory()->signup->create();
+               $args = array( 'fields' => 'ids' );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $found1 = BP_Signup::get(
-                       array(
-                               'fields' => 'ids',
-                       )
-               );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $found1 = BP_Signup::get( $args );
</ins><span class="cx" style="display: block; padding: 0 10px">                 $this->assertEqualSets( array( $s1 ), $found1['signups'] );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $s2 = self::factory()->signup->create();
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $found2 = BP_Signup::get(
-                       array(
-                               'fields' => 'ids',
-                       )
-               );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $found2 = BP_Signup::get( $args );
</ins><span class="cx" style="display: block; padding: 0 10px">                 $this->assertEqualSets( array( $s2 ), $found2['signups'] );
</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">@@ -520,7 +578,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertEqualSets( array( $s1, $s2 ), $found1['signups'] );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $activate = BP_Signup::activate( (array) $s2 );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         BP_Signup::activate( (array) $s2 );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $found2 = BP_Signup::get(
</span><span class="cx" style="display: block; padding: 0 10px">                        array(
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -569,7 +627,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertEquals( $s1, $found1->id );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertFalse( $found1->active );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $activate = BP_Signup::activate( (array) $s1 );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         BP_Signup::activate( (array) $s1 );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $found2 = new BP_Signup( $s1 );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertEquals( $s1, $found2->id );
</span></span></pre>
</div>
</div>

</body>
</html>