Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
03/29/2014 12:35:30 AM (10 years ago)
Author:
r-a-y
Message:

Cache the group invite count for a user.

This commit:

  • Caches calls to BP_Groups_Member::get_invite_count_for_user()
  • Invalidates the group invite count cache on various actions
  • Adds a unit test

See #5414

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-groups/bp-groups-classes.php

    r8168 r8200  
    23632363        $bp = buddypress();
    23642364
    2365         return (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(DISTINCT m.group_id) FROM {$bp->groups->table_name_members} m, {$bp->groups->table_name} g WHERE m.group_id = g.id AND m.is_confirmed = 0 AND m.inviter_id != 0 AND m.invite_sent = 1 AND m.user_id = %d ORDER BY date_modified ASC", $user_id ) );
     2365        $count = wp_cache_get( $user_id, 'bp_group_invite_count' );
     2366
     2367        if ( false === $count ) {
     2368            $count = (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(DISTINCT m.group_id) FROM {$bp->groups->table_name_members} m, {$bp->groups->table_name} g WHERE m.group_id = g.id AND m.is_confirmed = 0 AND m.inviter_id != 0 AND m.invite_sent = 1 AND m.user_id = %d", $user_id ) );
     2369            wp_cache_set( $user_id, $count, 'bp_group_invite_count' );
     2370        }
     2371
     2372        return $count;
    23662373    }
    23672374
Note: See TracChangeset for help on using the changeset viewer.