Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
09/01/2016 03:27:12 AM (8 years ago)
Author:
boonebgorges
Message:

Cache the results of activity ID and count queries.

Query results are cached using an incrementor, and are invalidated in
bulk whenever an activity item is created, updated, or deleted.

Fixes #7237.

File:
1 edited

Legend:

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

    r10908 r11054  
    646646            $activity_ids_sql = apply_filters( 'bp_activity_paged_activities_sql', $activity_ids_sql, $r );
    647647
    648             $activity_ids = $wpdb->get_col( $activity_ids_sql );
     648            $cached = bp_core_get_incremented_cache( $activity_ids_sql, 'bp_activity' );
     649            if ( false === $cached ) {
     650                $activity_ids = $wpdb->get_col( $activity_ids_sql );
     651                bp_core_set_incremented_cache( $activity_ids_sql, 'bp_activity', $activity_ids );
     652            } else {
     653                $activity_ids = $cached;
     654            }
    649655
    650656            $retval['has_more_items'] = ! empty( $per_page ) && count( $activity_ids ) > $per_page;
     
    703709             */
    704710            $total_activities_sql = apply_filters( 'bp_activity_total_activities_sql', "SELECT count(DISTINCT a.id) FROM {$bp->activity->table_name} a {$join_sql} {$where_sql}", $where_sql, $sort );
    705             $total_activities     = $wpdb->get_var( $total_activities_sql );
     711            $cached = bp_core_get_incremented_cache( $total_activities_sql, 'bp_activity' );
     712            if ( false === $cached ) {
     713                $total_activities = $wpdb->get_var( $total_activities_sql );
     714                bp_core_set_incremented_cache( $total_activities_sql, 'bp_activity', $total_activities );
     715            } else {
     716                $total_activities = $cached;
     717            }
    706718
    707719            if ( !empty( $r['max'] ) ) {
Note: See TracChangeset for help on using the changeset viewer.