Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
04/01/2015 11:14:16 PM (9 years ago)
Author:
johnjamesjacoby
Message:

XProfile: Introduce bp_xprofile_groups cache group, to replace bp cache group usage.

  • Reduces field group cache keys down to just their ID, using a unique cache group
  • Use all key instead of 'xprofile_groups_inc_empty`
  • Use default_visibility_levels key instead of xprofile_default_visibility_levels

See #6341, #5733.

File:
1 edited

Legend:

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

    r9351 r9676  
    5353 *        object type ('group', 'field', 'data')
    5454 */
    55 function bp_xprofile_update_meta_cache( $object_ids = array(), $user_id = 0 ) {
     55function bp_xprofile_update_meta_cache( $object_ids = array() ) {
    5656    global $wpdb;
    5757
     
    7676    foreach ( $uncached_object_ids as $object_type => $uncached_object_type_ids ) {
    7777        if ( ! empty( $object_ids[ $object_type ] ) ) {
     78
    7879            // Sanitize $object_ids passed to the function
    7980            $object_type_ids = wp_parse_id_list( $object_ids[ $object_type ] );
     
    9091
    9192    // If there are uncached items, go ahead with the query
    92     if ( $do_query ) {
     93    if ( true === $do_query ) {
    9394        $where = array();
    9495        foreach ( $uncached_object_ids as $otype => $oids ) {
     
    139140}
    140141
     142/**
     143 * Clear cached XProfile field group data
     144 *
     145 * @since BuddyPress (2.1.0)
     146 *
     147 * @param object $group_obj
     148 */
    141149function xprofile_clear_profile_groups_object_cache( $group_obj ) {
    142     wp_cache_delete( 'xprofile_groups_inc_empty',        'bp' );
    143     wp_cache_delete( 'xprofile_group_' . $group_obj->id, 'bp' );
     150    wp_cache_delete( 'all',          'bp_xprofile_groups' );
     151    wp_cache_delete( $group_obj->id, 'bp_xprofile_groups' );
    144152}
    145153add_action( 'xprofile_group_after_delete', 'xprofile_clear_profile_groups_object_cache' );
    146154add_action( 'xprofile_group_after_save',   'xprofile_clear_profile_groups_object_cache' );
    147155
    148 function xprofile_clear_profile_data_object_cache( $group_id ) {
    149     wp_cache_delete( 'bp_user_fullname_' . bp_loggedin_user_id(), 'bp' );
    150 }
    151 add_action( 'xprofile_updated_profile', 'xprofile_clear_profile_data_object_cache'   );
     156/**
     157 * Clear cached XProfile fullname data for user
     158 *
     159 * @since BuddyPress (2.1.0)
     160 *
     161 * @param int $user_id ID of user whose fullname cache to delete
     162 */
     163function xprofile_clear_profile_data_object_cache( $user_id = 0 ) {
     164    wp_cache_delete( 'bp_user_fullname_' . $user_id, 'bp' );
     165}
     166add_action( 'xprofile_updated_profile', 'xprofile_clear_profile_data_object_cache' );
    152167
    153168/**
     
    174189 */
    175190function xprofile_clear_profile_field_object_cache( $field_obj ) {
     191
    176192    // Clear default visibility level cache
    177     wp_cache_delete( 'xprofile_default_visibility_levels', 'bp' );
     193    wp_cache_delete( 'default_visibility_levels', 'bp_xprofile' );
    178194
    179195    // Modified fields can alter parent group status, in particular when
    180196    // the group goes from empty to non-empty. Bust its cache, as well as
    181     // the global group_inc_empty cache
    182     wp_cache_delete( 'xprofile_group_' . $field_obj->group_id, 'bp' );
    183     wp_cache_delete( 'xprofile_groups_inc_empty', 'bp' );
    184 }
    185 add_action( 'xprofile_fields_saved_field', 'xprofile_clear_profile_field_object_cache' );
     197    // the global 'all' cache
     198    wp_cache_delete( 'all',                'bp_xprofile_groups' );
     199    wp_cache_delete( $field_obj->group_id, 'bp_xprofile_groups' );
     200}
     201add_action( 'xprofile_fields_saved_field',   'xprofile_clear_profile_field_object_cache' );
    186202add_action( 'xprofile_fields_deleted_field', 'xprofile_clear_profile_field_object_cache' );
    187203
Note: See TracChangeset for help on using the changeset viewer.