Skip to:
Content

BuddyPress.org

Changeset 7843


Ignore:
Timestamp:
02/11/2014 04:51:43 AM (9 years ago)
Author:
boonebgorges
Message:

Modify bp_update_meta_cache() for new metadata cache schema

Now that we are using the WP metadata API, our cache keys have changed, and
the logic for priming meta caches must mirror these changes.

See #4551

Location:
trunk
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-core/bp-core-cache.php

    r7821 r7843  
    180180        'object_ids'       => array(), // Comma-separated list or array of item ids
    181181        'object_type'      => '',      // Canonical component id: groups, members, etc
     182        'cache_group'      => '',      // Cache group
    182183        'meta_table'       => '',      // Name of the table containing the metadata
    183184        'object_column'    => '',      // DB column for the object ids (group_id, etc)
     
    188189    extract( $r );
    189190
    190     if ( empty( $object_ids ) || empty( $object_type ) || empty( $meta_table ) ) {
     191    if ( empty( $object_ids ) || empty( $object_type ) || empty( $meta_table ) || empty( $cache_group ) ) {
    191192        return false;
    192193    }
     
    200201    }
    201202
    202     $object_ids = wp_parse_id_list( $object_ids );
     203    if ( ! $cache_group ) {
     204        return false;
     205    }
     206
     207    $object_ids   = wp_parse_id_list( $object_ids );
     208    $uncached_ids = bp_get_non_cached_ids( $object_ids, $cache_group );
    203209
    204210    $cache = array();
    205211
    206212    // Get meta info
    207     $id_list   = join( ',', $object_ids );
    208     $meta_list = $wpdb->get_results( $wpdb->prepare( "SELECT {$object_column}, meta_key, meta_value FROM {$meta_table} WHERE {$object_column} IN ($id_list)", $object_type ), ARRAY_A );
    209 
    210     if ( !empty( $meta_list ) ) {
    211         foreach ( $meta_list as $metarow ) {
    212             $mpid = intval( $metarow[$object_column] );
    213             $mkey = $metarow['meta_key'];
    214             $mval = $metarow['meta_value'];
    215 
    216             // Force subkeys to be array type:
    217             if ( !isset( $cache[$mpid] ) || !is_array( $cache[$mpid] ) )
    218                 $cache[$mpid] = array();
    219             if ( !isset( $cache[$mpid][$mkey] ) || !is_array( $cache[$mpid][$mkey] ) )
    220                 $cache[$mpid][$mkey] = array();
    221 
    222             // Add a value to the current pid/key:
    223             $cache[$mpid][$mkey][] = $mval;
     213    if ( ! empty( $uncached_ids ) ) {
     214        $id_list   = join( ',', $object_ids );
     215        $meta_list = $wpdb->get_results( $wpdb->prepare( "SELECT {$object_column}, meta_key, meta_value FROM {$meta_table} WHERE {$object_column} IN ($id_list)", $object_type ), ARRAY_A );
     216
     217        if ( ! empty( $meta_list ) ) {
     218            foreach ( $meta_list as $metarow ) {
     219                $mpid = intval( $metarow[$object_column] );
     220                $mkey = $metarow['meta_key'];
     221                $mval = $metarow['meta_value'];
     222
     223                // Force subkeys to be array type:
     224                if ( !isset( $cache[$mpid] ) || !is_array( $cache[$mpid] ) )
     225                    $cache[$mpid] = array();
     226                if ( !isset( $cache[$mpid][$mkey] ) || !is_array( $cache[$mpid][$mkey] ) )
     227                    $cache[$mpid][$mkey] = array();
     228
     229                // Add a value to the current pid/key:
     230                $cache[$mpid][$mkey][] = $mval;
     231            }
    224232        }
    225     }
    226 
    227     foreach ( $object_ids as $id ) {
    228         if ( ! isset($cache[$id]) )
    229             $cache[$id] = array();
    230 
    231         foreach( $cache[$id] as $meta_key => $meta_value ) {
    232             wp_cache_set( $cache_key_prefix . '_' . $id . '_' . $meta_key, $meta_value, 'bp' );
     233
     234        foreach ( $cache as $object_id => $cache_val ) {
     235            wp_cache_set( $object_id, $cache_val, $cache_group );
    233236        }
    234237    }
  • trunk/bp-groups/bp-groups-cache.php

    r7645 r7843  
    3434        'object_ids'       => $group_ids,
    3535        'object_type'      => $bp->groups->id,
     36        'cache_group'      => 'group_meta',
    3637        'object_column'    => 'group_id',
    3738        'meta_table'       => $bp->groups->table_name_groupmeta,
Note: See TracChangeset for help on using the changeset viewer.