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/src/bp-groups/bp-groups-functions.php

    r9226 r9231  
    645645 */
    646646function groups_get_total_group_count() {
    647     if ( !$count = wp_cache_get( 'bp_total_group_count', 'bp' ) ) {
     647    $count = wp_cache_get( 'bp_total_group_count', 'bp' );
     648
     649    if ( false === $count ) {
    648650        $count = BP_Groups_Group::get_total_group_count();
    649651        wp_cache_set( 'bp_total_group_count', $count, 'bp' );
     
    685687        $user_id = ( bp_displayed_user_id() ) ? bp_displayed_user_id() : bp_loggedin_user_id();
    686688
    687     if ( !$count = wp_cache_get( 'bp_total_groups_for_user_' . $user_id, 'bp' ) ) {
     689    $count = wp_cache_get( 'bp_total_groups_for_user_' . $user_id, 'bp' );
     690
     691    if ( false === $count ) {
    688692        $count = BP_Groups_Member::total_group_count( $user_id );
    689693        wp_cache_set( 'bp_total_groups_for_user_' . $user_id, $count, 'bp' );
Note: See TracChangeset for help on using the changeset viewer.