Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
03/29/2014 12:35:30 AM (12 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-cache.php

    r7956 r8200  
    113113
    114114/**
     115 * Clear a user's cached total group invite count.
     116 *
     117 * Count is cleared when an invite is accepted, rejected or deleted.
     118 *
     119 * @since BuddyPress (2.0.0)
     120 *
     121 * @param int $user_id The user ID.
     122 */
     123function bp_groups_clear_invite_count_for_user( $user_id ) {
     124        wp_cache_delete( $user_id, 'bp_group_invite_count' );
     125}
     126add_action( 'groups_accept_invite', 'bp_groups_clear_invite_count_for_user' );
     127add_action( 'groups_reject_invite', 'bp_groups_clear_invite_count_for_user' );
     128add_action( 'groups_delete_invite', 'bp_groups_clear_invite_count_for_user' );
     129
     130/**
     131 * Clear a user's cached total group invite count when a user is uninvited.
     132 *
     133 * Groan. Our API functions are not consistent.
     134 *
     135 * @since BuddyPress (2.0.0)
     136 *
     137 * @param int $group_id The group ID. Not used in this function.
     138 * @param int $user_id The user ID.
     139 */
     140function bp_groups_clear_invite_count_on_uninvite( $group_id, $user_id ) {
     141        bp_groups_clear_invite_count_for_user( $user_id );
     142}
     143add_action( 'groups_uninvite_user', 'bp_groups_clear_invite_count_on_uninvite', 10, 2 );
     144
     145/**
     146 * Clear a user's cached total group invite count when a new invite is sent.
     147 *
     148 * @since BuddyPress (2.0.0)
     149 *
     150 * @param int $group_id The group ID. Not used in this function.
     151 * @param array $invited_users Array of invited user IDs.
     152 */
     153function bp_groups_clear_invite_count_on_send( $group_id, $invited_users ) {
     154        foreach ( $invited_users as $user_id ) {
     155                bp_groups_clear_invite_count_for_user( $user_id );
     156        }
     157}
     158add_action( 'groups_send_invites', 'bp_groups_clear_invite_count_on_send', 10, 2 );
     159
     160/**
    115161 * Clear a user's cached group count.
    116162 *
    117  * @param int $group_id ID of the group. Not used in this function.
    118  * @param int $user_id ID of the user whose group count is being changed.
     163 * @param int $group_id The group ID. Not used in this function.
     164 * @param int $user_id The user ID.
    119165 */
    120166function groups_clear_group_user_object_cache( $group_id, $user_id ) {
Note: See TracChangeset for help on using the changeset viewer.