Skip to:
Content

bbPress.org


Ignore:
Timestamp:
12/11/2019 04:05:40 PM (5 years ago)
Author:
johnjamesjacoby
Message:

Engagements: fix bugs with caching implementation in User strategy.

This commit adds the $object_id to the end of the cache key, to avoid collisions with other IDs. It also loosens 2 explicit true comparisons because internal calls to update_meta() up the stack may return an integer.

See #3292. For 2.7, trunk.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/includes/common/engagements.php

    r7006 r7024  
    612612    private function get_cache_key( $meta_key = '', $object_id = 0 ) {
    613613
     614        // No negative numbers in cache keys
     615        $object_id = absint( $object_id );
     616
    614617        // Maybe guess at post type
    615618        $post_type = ! empty( $object_id )
     
    641644        }
    642645
    643         // Return the old (pluralized) user option key
    644         return $key;
     646        // Return the old (pluralized) user option key with object ID appended
     647        return "{$key}{$object_id}";
    645648    }
    646649
     
    661664        $cache_key = $this->get_cache_key( $meta_key, $object_id );
    662665
    663         return wp_cache_get( $cache_key, 'bbpress_users' );
     666        return wp_cache_get( $cache_key, 'bbpress_posts' );
    664667    }
    665668
     
    740743            $retval       = update_user_option( $user_id, $option_key, $object_ids );
    741744
    742             // Delete cache, if successful
    743             if ( true === $retval ) {
     745            // Delete cache if successful (accounts for int & true)
     746            if ( false !== $retval ) {
    744747                $this->cache_delete( $meta_key, $object_id );
    745748            }
     
    777780                : delete_user_option( $user_id, $option_key );
    778781
    779             // Delete cache, if successful
    780             if ( true === $retval ) {
     782            // Delete cache if successful (accounts for int & true)
     783            if ( false !== $retval ) {
    781784                $this->cache_delete( $meta_key, $object_id );
    782785            }
     
    806809        $object_ids = $this->parse_comma_list( get_user_option( $option_key, $user_id ) );
    807810
    808         // Attempt to delete the
     811        // Attempt to delete the user option
    809812        $retval = delete_user_option( $user_id, $option_key );
    810813
     
    945948        $object_ids = $this->parse_comma_list( get_user_option( $option_key, $user_id ) );
    946949
    947         // Maybe trick WP_Query into ".ID IN ()"
     950        // Maybe trick WP_Query into ".ID IN (0)" to return no results
    948951        if ( empty( $object_ids ) ) {
    949952            $object_ids = array( 0 );
Note: See TracChangeset for help on using the changeset viewer.