Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
09/14/2016 02:06:10 AM (9 years ago)
Author:
boonebgorges
Message:

Activity: Invalidate query caches when a user's 'last_activity' is updated.

User 'last_activity' is stored in the activity table, but not updated
via the Activity API, so regular invalidation techniques do not work.

In addition, 'last_activity' is quite frequently updated, meaning that
the activity query cache becomes less valuable. To mitigate this, the
current changeset separates the cache for queries containing
'last_activity' from the cache for those that do not.

Fixes #7245.

File:
1 edited

Legend:

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

    r11054 r11101  
    646646            $activity_ids_sql = apply_filters( 'bp_activity_paged_activities_sql', $activity_ids_sql, $r );
    647647
    648             $cached = bp_core_get_incremented_cache( $activity_ids_sql, 'bp_activity' );
     648            /*
     649             * Queries that include 'last_activity' are cached separately,
     650             * since they are generally much less long-lived.
     651             */
     652            if ( preg_match( '/a\.type NOT IN \([^\)]*\'last_activity\'[^\)]*\)/', $activity_ids_sql ) ) {
     653                $cache_group = 'bp_activity';
     654            } else {
     655                $cache_group = 'bp_activity_with_last_activity';
     656            }
     657
     658            $cached = bp_core_get_incremented_cache( $activity_ids_sql, $cache_group );
    649659            if ( false === $cached ) {
    650660                $activity_ids = $wpdb->get_col( $activity_ids_sql );
    651                 bp_core_set_incremented_cache( $activity_ids_sql, 'bp_activity', $activity_ids );
     661                bp_core_set_incremented_cache( $activity_ids_sql, $cache_group, $activity_ids );
    652662            } else {
    653663                $activity_ids = $cached;
     
    709719             */
    710720            $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 );
    711             $cached = bp_core_get_incremented_cache( $total_activities_sql, 'bp_activity' );
     721            $cached = bp_core_get_incremented_cache( $total_activities_sql, $cache_group );
    712722            if ( false === $cached ) {
    713723                $total_activities = $wpdb->get_var( $total_activities_sql );
    714                 bp_core_set_incremented_cache( $total_activities_sql, 'bp_activity', $total_activities );
     724                bp_core_set_incremented_cache( $total_activities_sql, $cache_group, $total_activities );
    715725            } else {
    716726                $total_activities = $cached;
Note: See TracChangeset for help on using the changeset viewer.