Skip to:
Content

BuddyPress.org

Changeset 9676


Ignore:
Timestamp:
04/01/2015 11:14:16 PM (12 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.

Location:
trunk/src/bp-xprofile
Files:
4 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
  • trunk/src/bp-xprofile/bp-xprofile-loader.php

    r9515 r9676  
    368368                        'bp_xprofile',
    369369                        'bp_xprofile_data',
     370                        'bp_xprofile_groups',
    370371                        'xprofile_meta'
    371372                ) );
  • trunk/src/bp-xprofile/bp-xprofile-template.php

    r9515 r9676  
    881881 */
    882882function bp_profile_get_field_groups() {
    883         $groups = wp_cache_get( 'xprofile_groups_inc_empty', 'bp' );
    884 
    885         if ( empty( $groups ) ) {
     883
     884        $groups = wp_cache_get( 'all', 'bp_xprofile_groups' );
     885        if ( false === $groups ) {
    886886                $groups = bp_xprofile_get_groups( array( 'fetch_fields' => true ) );
    887                 wp_cache_set( 'xprofile_groups_inc_empty', $groups, 'bp' );
     887                wp_cache_set( 'all', $groups, 'bp_xprofile' );
    888888        }
    889889
    … …  
    974974}
    975975        function bp_get_profile_group_name() {
    976                 if ( !$group_id = bp_action_variable( 1 ) )
     976
     977                // Check action variable
     978                $group_id = bp_action_variable( 1 );
     979                if ( empty( $group_id ) || ! is_numeric( $group_id ) ) {
    977980                        $group_id = 1;
    978 
    979                 if ( !is_numeric( $group_id ) )
    980                         $group_id = 1;
    981 
    982                 if ( !$group = wp_cache_get( 'xprofile_group_' . $group_id, 'bp' ) ) {
    983                         $group = new BP_XProfile_Group($group_id);
    984                         wp_cache_set( 'xprofile_group_' . $group_id, $group, 'bp' );
    985                 }
     981                }
     982
     983                // Check for cached group
     984                $group = new BP_XProfile_Group( $group_id );
    986985
    987986                /**
  • trunk/src/bp-xprofile/classes/class-bp-xprofile-group.php

    r9671 r9676  
    8282                global $wpdb;
    8383
    84                 $group = wp_cache_get( 'xprofile_group_' . $this->id, 'bp' );
     84                $group = wp_cache_get( $id, 'bp_xprofile_groups' );
    8585
    8686                if ( false === $group ) {
    87                         $bp = buddypress();
     87                        $bp    = buddypress();
    8888                        $group = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->profile->table_name_groups} WHERE id = %d", $id ) );
     89                        wp_cache_set( $id, $group, 'bp_xprofile_groups' );
    8990                }
    9091
    … …  
    9495
    9596                $this->id          = $group->id;
    96                 $this->name        = stripslashes( $group->name );
    97                 $this->description = stripslashes( $group->description );
     97                $this->name        = $group->name;
     98                $this->description = $group->description;
    9899                $this->can_delete  = $group->can_delete;
    99100                $this->group_order = $group->group_order;
    … …  
    456457
    457458                        // If cached data is found, use it
    458                         $cache_key  = 'xprofile_group_' . $group_id;
    459                         $group_data = wp_cache_get( $cache_key, 'bp' );
     459                        $group_data = wp_cache_get( $group_id, 'bp_xprofile_groups' );
    460460                        if ( false !== $group_data ) {
    461461                                $groups[ $group_id ] = $group_data;
    … …  
    493493
    494494                                        // Cache previously uncached group data
    495                                         $cache_key = 'xprofile_group_' . $gdata->id;
    496                                         wp_cache_set( $cache_key, $gdata, 'bp' );
     495                                        wp_cache_set( $gdata->id, $gdata, 'bp_xprofile_groups' );
    497496                                }
    498497                        }
    … …  
    543542
    544543                // Purge profile field group cache
    545                 wp_cache_delete( 'xprofile_groups_inc_empty', 'bp' );
     544                wp_cache_delete( 'all', 'bp_xprofile_groups' );
    546545
    547546                $bp = buddypress();
    … …  
    608607                global $wpdb;
    609608
    610                 $default_visibility_levels = wp_cache_get( 'xprofile_default_visibility_levels', 'bp' );
     609                $default_visibility_levels = wp_cache_get( 'default_visibility_levels', 'bp_xprofile' );
    611610
    612611                if ( false === $default_visibility_levels ) {
    … …  
    628627                        }
    629628
    630                         wp_cache_set( 'xprofile_default_visibility_levels', $default_visibility_levels, 'bp' );
     629                        wp_cache_set( 'default_visibility_levels', $default_visibility_levels, 'bp_xprofile' );
    631630                }
    632631
Note: See TracChangeset for help on using the changeset viewer.