Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
12/15/2014 08:38:11 PM (12 years ago)
Author:
r-a-y
Message:

Check cache for count functions that return zero.

Some of our count functions were previously setting counts of zero
correctly, but the functions themselves were not referencing the cache
properly when the count returned zero. This led to unnecessary database
queries and we hate extra queries!

This commit addresses the problem and adds unit tests.

Props r-a-y, boonebgorges.

Fixes #6012.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/testcases/groups/cache.php

    r9156 r9231  
    201201                $this->assertEquals( 2, count( groups_get_group_admins( $g ) ) );
    202202        }
     203
     204        /**
     205         * @group groups_get_total_group_count
     206         * @group counts
     207         */
     208        public function test_groups_get_total_group_count_should_respect_cached_value_of_0() {
     209                global $wpdb;
     210
     211                // prime cache
     212                // no groups are created by default, so count is zero
     213                groups_get_total_group_count();
     214                $first_query_count = $wpdb->num_queries;
     215
     216                // run function again
     217                groups_get_total_group_count();
     218
     219                // check if function references cache or hits the DB by comparing query count
     220                $this->assertEquals( $first_query_count, $wpdb->num_queries );
     221        }
    203222}
Note: See TracChangeset for help on using the changeset viewer.