Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
01/09/2015 08:38:37 PM (10 years ago)
Author:
johnjamesjacoby
Message:

XProfile data cache group updates:

  • Switches from dynamic cache group to unique key for $user_id:$field_id.
  • Introduces bp_xprofile_get_non_cached_field_ids() as a helper, based on bp_get_non_cached_field_ids().
  • Registers bp_xprofile and bp_xprofile_data as global cache groups.
  • Updates unit tests to pass with new cache keys.

Props r-a-y. Fixes #6100. See #5733.

File:
1 edited

Legend:

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

    r9329 r9336  
    12231223        global $wpdb, $bp;
    12241224
    1225         $cache_group = 'bp_xprofile_data_' . $user_id;
    1226         $profiledata = wp_cache_get( $field_id, $cache_group );
     1225        $cache_key   = "{$user_id}:{$field_id}";
     1226        $profiledata = wp_cache_get( $cache_key, 'bp_xprofile_data' );
    12271227
    12281228        if ( false === $profiledata ) {
    1229             $sql = $wpdb->prepare( "SELECT * FROM {$bp->profile->table_name_data} WHERE field_id = %d AND user_id = %d", $field_id, $user_id );
     1229            $sql         = $wpdb->prepare( "SELECT * FROM {$bp->profile->table_name_data} WHERE field_id = %d AND user_id = %d", $field_id, $user_id );
    12301230            $profiledata = $wpdb->get_row( $sql );
    12311231
    12321232            if ( $profiledata ) {
    1233                 wp_cache_set( $field_id, $profiledata, $cache_group );
     1233                wp_cache_set( $cache_key, $profiledata, 'bp_xprofile_data' );
    12341234            }
    12351235        }
     
    12601260
    12611261        // Check cache first
    1262         $cached = wp_cache_get( $this->field_id, 'bp_xprofile_data_' . $this->user_id );
     1262        $cache_key = "{$this->user_id}:{$this->field_id}";
     1263        $cached    = wp_cache_get( $cache_key, 'bp_xprofile_data' );
    12631264
    12641265        if ( $cached && ! empty( $cached->id ) ) {
     
    14011402        $data = array();
    14021403
    1403         $cache_group = 'bp_xprofile_data_' . $user_id;
    1404 
    1405         $uncached_field_ids = bp_get_non_cached_ids( $field_ids, $cache_group );
     1404        $uncached_field_ids = bp_xprofile_get_non_cached_field_ids( $user_id, $field_ids, 'bp_xprofile_data' );
    14061405
    14071406        // Prime the cache
     
    14271426            foreach ( $uncached_field_ids as $field_id ) {
    14281427
     1428                $cache_key = "{$user_id}:{$field_id}";
     1429
    14291430                // If a value was found, cache it
    14301431                if ( isset( $queried_data[ $field_id ] ) ) {
    1431                     wp_cache_set( $field_id, $queried_data[ $field_id ], $cache_group );
     1432                    wp_cache_set( $cache_key, $queried_data[ $field_id ], 'bp_xprofile_data' );
    14321433
    14331434                // If no value was found, cache an empty item
     
    14411442                    $d->last_updated = '';
    14421443
    1443                     wp_cache_set( $field_id, $d, $cache_group );
     1444                    wp_cache_set( $cache_key, $d, 'bp_xprofile_data' );
    14441445                }
    14451446            }
     
    14481449        // Now that all items are cached, fetch them
    14491450        foreach ( $field_ids as $field_id ) {
    1450             $data[] = wp_cache_get( $field_id, $cache_group );
     1451            $cache_key = "{$user_id}:{$field_id}";
     1452            $data[]    = wp_cache_get( $cache_key, 'bp_xprofile_data' );
    14511453        }
    14521454
     
    14611463     */
    14621464    public static function get_all_for_user( $user_id ) {
    1463         global $wpdb, $bp;
    14641465
    14651466        $groups = bp_xprofile_get_groups( array(
     
    15151516
    15161517            // Check cache first
    1517             $fielddata = wp_cache_get( $field_id, 'bp_xprofile_data_' . $user_id );
     1518            $cache_key = "{$user_id}:{$field_id}";
     1519            $fielddata = wp_cache_get( $cache_key, 'bp_xprofile_data' );
    15181520            if ( false === $fielddata || empty( $fielddata->id ) ) {
    15191521                $fielddata_id = $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->profile->table_name_data} WHERE field_id = %d AND user_id = %d", $field_id, $user_id ) );
     
    15521554        $uncached_ids = array();
    15531555        foreach ( $user_ids as $user_id ) {
    1554             if ( false === wp_cache_get( $field_id, 'bp_xprofile_data_' . $user_id ) ) {
     1556            $cache_key = "{$user_id}:{$field_id}";
     1557            if ( false === wp_cache_get( $cache_key, 'bp_xprofile_data' ) ) {
    15551558                $uncached_ids[] = $user_id;
    15561559            }
     
    15841587                }
    15851588
    1586                 wp_cache_set( $field_id, $d, 'bp_xprofile_data_' . $d->user_id );
     1589                $cache_key = "{$d->user_id}:{$field_id}";
     1590                wp_cache_set( $cache_key, $d, 'bp_xprofile_data' );
    15871591            }
    15881592        }
     
    15911595        $data = array();
    15921596        foreach ( $user_ids as $user_id ) {
    1593             $data[] = wp_cache_get( $field_id, 'bp_xprofile_data_' . $user_id );
     1597            $cache_key = "{$user_id}:{$field_id}";
     1598            $data[]    = wp_cache_get( $cache_key, 'bp_xprofile_data' );
    15941599        }
    15951600
Note: See TracChangeset for help on using the changeset viewer.