Skip to:
Content

BuddyPress.org

Changeset 7773


Ignore:
Timestamp:
02/03/2014 02:43:51 AM (10 years ago)
Author:
boonebgorges
Message:

Fix persistent caching for BP_Activity_Activity::get_activity_comments()

  • Use the 'bp' cache group consistently
  • When a query shows that an activity item has no comments, do not cache the boolean value false. This will cause a cache miss the next time around. Instead, store the string 'none', and then convert it to false when requerying.

Fixes #5369

Location:
trunk/bp-activity
Files:
2 edited

Legend:

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

    r7771 r7773  
    868868        }
    869869
    870         if ( !$comments = wp_cache_get( 'bp_activity_comments_' . $activity_id ) ) {
     870        $comments = wp_cache_get( 'bp_activity_comments_' . $activity_id, 'bp' );
     871
     872        // We store the string 'none' to cache the fact that the
     873        // activity item has no comments
     874        if ( 'none' === $comments ) {
     875            $comments = false;
     876
     877        // A true cache miss
     878        } else if ( empty( $comments ) ) {
    871879
    872880            // Select the user's fullname with the query
     
    912920                }
    913921            }
    914             wp_cache_set( 'bp_activity_comments_' . $activity_id, $comments, 'bp' );
     922
     923            // If we cache a value of false, it'll count as a cache
     924            // miss the next time the activity comments are fetched.
     925            // Storing the string 'none' is a hack workaround to
     926            // avoid unnecessary queries.
     927            if ( false === $comments ) {
     928                $cache_value = 'none';
     929            } else {
     930                $cache_value = $comments;
     931            }
     932
     933            wp_cache_set( 'bp_activity_comments_' . $activity_id, $cache_value, 'bp' );
    915934        }
    916935
  • trunk/bp-activity/bp-activity-functions.php

    r7622 r7773  
    12531253
    12541254    // Clear the comment cache for this activity
    1255     wp_cache_delete( 'bp_activity_comments_' . $parent_id );
     1255    wp_cache_delete( 'bp_activity_comments_' . $parent_id, 'bp' );
    12561256
    12571257    do_action( 'bp_activity_comment_posted', $comment_id, $params, $activity );
Note: See TracChangeset for help on using the changeset viewer.