Skip to:
Content

BuddyPress.org

Changeset 7820


Ignore:
Timestamp:
02/07/2014 02:04:52 AM (11 years ago)
Author:
boonebgorges
Message:

Ensure that a cache value is set for empty items in BP_XProfile_ProfileData::get_value_byid()

See #1332

File:
1 edited

Legend:

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

    r7812 r7820  
    13861386            $queried_data = $wpdb->get_results( $wpdb->prepare( "SELECT id, user_id, field_id, value, last_updated FROM {$bp->profile->table_name_data} WHERE field_id = %d AND user_id IN ({$uncached_ids_sql})", $field_id ) );
    13871387
    1388             foreach ( $queried_data as $d ) {
     1388            // Rekey
     1389            $qd = array();
     1390            foreach ( $queried_data as $data ) {
     1391                $qd[ $data->user_id ] = $data;
     1392            }
     1393
     1394            foreach ( $uncached_ids as $id ) {
     1395                // The value was successfully fetched
     1396                if ( isset( $qd[ $id ] ) ) {
     1397                    $d = $qd[ $id ];
     1398
     1399                // No data found for the user, so we fake it to
     1400                // avoid cache misses and PHP notices
     1401                } else {
     1402                    $d = new stdClass;
     1403                    $d->id           = '';
     1404                    $d->user_id      = $id;
     1405                    $d->field_id     = '';
     1406                    $d->value        = '';
     1407                    $d->last_updated = '';
     1408                }
     1409
    13891410                wp_cache_set( $field_id, $d, 'bp_xprofile_data_' . $d->user_id );
    13901411            }
Note: See TracChangeset for help on using the changeset viewer.