Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
08/31/2021 09:46:50 PM (3 years ago)
Author:
dcavins
Message:

Improve BP_Signup class.

  • Add caching for BP_Signup SQL queries and BP_Signup objects.
  • Synchronize signup result format provided by get() and construct() methods.
  • Add action points so that the cache items can be cleaned up.
  • Use cached functions rather than making direct database calls.
  • Improve behavior of meta updating method.

Fixes #8540.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-members/bp-members-cache.php

    r11110 r13098  
    7474}
    7575add_action( 'bp_core_user_updated_last_activity', 'bp_members_reset_activity_cache_incrementor' );
     76
     77/**
     78 * Bust signup caches when editing or deleting.
     79 *
     80 * @since 10.0.0
     81 *
     82 * @param int $signup_id The ID of the signup affected.
     83 */
     84function bp_members_delete_signup_cache( $signup_id = 0 ) {
     85    wp_cache_delete( $signup_id, 'bp_signups' );
     86}
     87add_action( 'bp_core_signups_after_add',         'bp_members_delete_signup_cache' );
     88add_action( 'bp_core_signups_after_update_meta', 'bp_members_delete_signup_cache' );
     89
     90/**
     91 * Bust signup caches for arrays of signup IDs.
     92 *
     93 * @since 10.0.0
     94 *
     95 * @param array $signup_ids The IDs of the signups affected.
     96 */
     97function bp_members_delete_signup_cache_multiples( $signup_ids = array() ) {
     98    // Ensure that the incoming item is an array.
     99    $signup_ids = wp_parse_id_list( $signup_ids );
     100    foreach ( $signup_ids as $signup_id ) {
     101        bp_members_delete_signup_cache( $signup_id );
     102    }
     103}
     104add_action( 'bp_core_signup_after_resend',   'bp_members_delete_signup_cache_multiples' );
     105add_action( 'bp_core_signup_after_activate', 'bp_members_delete_signup_cache_multiples' );
     106add_action( 'bp_core_signup_after_delete',   'bp_members_delete_signup_cache_multiples' );
     107
     108/**
     109 * Reset cache incrementor for BP_Signups.
     110 *
     111 * This function invalidates all cached results of BP_Signup queries,
     112 * whenever one of the following events takes place:
     113 *   - A record is created or updated.
     114 *   - A record is deleted.
     115 *
     116 * @since 10.0.0
     117 *
     118 * @return bool True on success, false on failure.
     119 */
     120function bp_members_reset_signup_cache_incrementor() {
     121    return bp_core_reset_incrementor( 'bp_signups' );
     122}
     123add_filter( 'bp_core_signups_after_add',         'bp_members_reset_signup_cache_incrementor' );
     124add_action( 'bp_core_activated_user',            'bp_members_reset_signup_cache_incrementor' );
     125add_action( 'bp_core_signup_after_activate',     'bp_members_reset_signup_cache_incrementor' );
     126add_action( 'bp_core_signups_after_update_meta', 'bp_members_reset_signup_cache_incrementor' );
     127add_action( 'bp_core_signup_after_delete',       'bp_members_reset_signup_cache_incrementor' );
     128
Note: See TracChangeset for help on using the changeset viewer.