Skip to:
Content

BuddyPress.org

Changeset 8075


Ignore:
Timestamp:
03/07/2014 01:32:01 AM (10 years ago)
Author:
boonebgorges
Message:

Normalize cache priming in BP_Activity_Activity::get_activity_data()

No need to reproduce logic in bp_get_non_cached_ids(). This brings the caching
strategy in line with other components.

See #5434

File:
1 edited

Legend:

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

    r8071 r8075  
    471471        $bp = buddypress();
    472472
    473         $activities = array();
    474         $query_aids = array();
    475 
    476         foreach ( $activity_ids as $activity_id ) {
    477 
    478             // If cached data is found, use it
    479             if ( $activity_data = wp_cache_get( $activity_id, 'bp_activity' ) ) {
    480                 $activities[ $activity_id ] = $activity_data;
    481 
    482             // Otherwise leave a placeholder so we don't lose the order
    483             } else {
    484                 $activities[ $activity_id ] = '';
    485 
    486                 // Add to the list to be queried
    487                 $query_aids[] = $activity_id;
    488             }
    489         }
    490 
    491         // Fetch activity data from the DB if necessary
    492         if ( ! empty( $query_aids ) ) {
     473        $activities   = array();
     474        $uncached_ids = bp_get_non_cached_ids( $activity_ids, 'bp_activity' );
     475
     476        // Prime caches as necessary
     477        if ( ! empty( $uncached_ids ) ) {
    493478            // Format the activity ID's for use in the query below
    494             $query_aids_sql = implode( ',', wp_parse_id_list( $query_aids ) );
     479            $uncached_ids_sql = implode( ',', wp_parse_id_list( $uncached_ids ) );
    495480
    496481            // Fetch data from activity table, preserving order
    497             $queried_adata = $wpdb->get_results( "SELECT * FROM {$bp->activity->table_name} WHERE id IN ({$query_aids_sql}) ORDER BY FIELD( id, {$query_aids_sql} )");
     482            $queried_adata = $wpdb->get_results( "SELECT * FROM {$bp->activity->table_name} WHERE id IN ({$uncached_ids_sql})");
    498483
    499484            // Put that data into the placeholders created earlier,
    500485            // and add it to the cache
    501486            foreach ( (array) $queried_adata as $adata ) {
    502                 $activities[ $adata->id ] = $adata;
    503487                wp_cache_set( $adata->id, $adata, 'bp_activity' );
    504488            }
    505489        }
    506490
    507         // Reset indexes
    508         $activities = array_values( $activities );
     491        // Now fetch data from the cache
     492        foreach ( $activity_ids as $activity_id ) {
     493            $activities[] = wp_cache_get( $activity_id, 'bp_activity' );
     494        }
    509495
    510496        // Then fetch user data
Note: See TracChangeset for help on using the changeset viewer.