Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
12/15/2014 08:38:11 PM (11 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/blogs/cache.php

    r9139 r9231  
    232232        $this->set_current_user( $old_user );
    233233    }
     234
     235    /**
     236     * @group bp_blogs_total_blogs
     237     * @group counts
     238     */
     239    public function test_bp_blogs_total_count_should_respect_cached_value_of_0() {
     240        if ( ! is_multisite() ) {
     241            return;
     242        }
     243
     244        global $wpdb;
     245
     246        // prime cache
     247        // no blogs are created by default, so count is zero
     248        bp_blogs_total_blogs();
     249        $first_query_count = $wpdb->num_queries;
     250
     251        // run function again
     252        bp_blogs_total_blogs();
     253
     254        // check if function references cache or hits the DB by comparing query count
     255        $this->assertEquals( $first_query_count, $wpdb->num_queries );
     256    }
    234257}
Note: See TracChangeset for help on using the changeset viewer.