Skip to:
Content

BuddyPress.org

Changeset 11076


Ignore:
Timestamp:
09/09/2016 04:04:36 PM (4 years ago)
Author:
boonebgorges
Message:

Activity: Invalidate query cache when activity meta is modified.

See #7237.

Location:
trunk
Files:
2 edited

Legend:

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

    r11054 r11076  
    8080add_action( 'bp_activity_delete', 'bp_activity_reset_cache_incrementor' );
    8181add_action( 'bp_activity_add', 'bp_activity_reset_cache_incrementor' );
     82add_action( 'added_activity_meta', 'bp_activity_reset_cache_incrementor' );
     83add_action( 'updated_activity_meta', 'bp_activity_reset_cache_incrementor' );
     84add_action( 'deleted_activity_meta', 'bp_activity_reset_cache_incrementor' );
  • trunk/tests/phpunit/testcases/activity/cache.php

    r11054 r11076  
    273273        $this->assertSame( $num_queries + 2, $wpdb->num_queries );
    274274    }
     275
     276    /**
     277     * @ticket BP7237
     278     * @ticket BP6643
     279     */
     280    public function test_query_cache_should_be_invalidated_by_activitymeta_add() {
     281        global $wpdb;
     282
     283        $activities = $this->factory->activity->create_many( 2 );
     284        bp_activity_add_meta( $activities[0], 'foo', 'bar' );
     285
     286        $activity_args = array(
     287            'meta_query' => array(
     288                array(
     289                    'key' => 'foo',
     290                    'value' => 'bar',
     291                ),
     292            ),
     293        );
     294
     295        $q1 = bp_activity_get( $activity_args );
     296        $this->assertEqualSets( array( $activities[0] ), wp_list_pluck( $q1['activities'], 'id' ) );
     297
     298        bp_activity_add_meta( $activities[1], 'foo', 'bar' );
     299
     300        $q2 = bp_activity_get( $activity_args );
     301        $this->assertEqualSets( array( $activities[0], $activities[1] ), wp_list_pluck( $q2['activities'], 'id' ) );
     302    }
     303
     304    /**
     305     * @ticket BP7237
     306     * @ticket BP6643
     307     */
     308    public function test_query_cache_should_be_invalidated_by_activitymeta_update() {
     309        global $wpdb;
     310
     311        $activities = $this->factory->activity->create_many( 2 );
     312        bp_activity_add_meta( $activities[0], 'foo', 'bar' );
     313        bp_activity_add_meta( $activities[1], 'foo', 'baz' );
     314
     315        $activity_args = array(
     316            'meta_query' => array(
     317                array(
     318                    'key' => 'foo',
     319                    'value' => 'bar',
     320                ),
     321            ),
     322        );
     323
     324        $q1 = bp_activity_get( $activity_args );
     325        $this->assertEqualSets( array( $activities[0] ), wp_list_pluck( $q1['activities'], 'id' ) );
     326
     327        bp_activity_update_meta( $activities[1], 'foo', 'bar' );
     328
     329        $q2 = bp_activity_get( $activity_args );
     330        $this->assertEqualSets( array( $activities[0], $activities[1] ), wp_list_pluck( $q2['activities'], 'id' ) );
     331    }
     332
     333    /**
     334     * @ticket BP7237
     335     * @ticket BP6643
     336     */
     337    public function test_query_cache_should_be_invalidated_by_activitymeta_delete() {
     338        global $wpdb;
     339
     340        $activities = $this->factory->activity->create_many( 2 );
     341        bp_activity_add_meta( $activities[0], 'foo', 'bar' );
     342        bp_activity_add_meta( $activities[1], 'foo', 'bar' );
     343
     344        $activity_args = array(
     345            'meta_query' => array(
     346                array(
     347                    'key' => 'foo',
     348                    'value' => 'bar',
     349                ),
     350            ),
     351        );
     352
     353        $q1 = bp_activity_get( $activity_args );
     354        $this->assertEqualSets( array( $activities[0], $activities[1] ), wp_list_pluck( $q1['activities'], 'id' ) );
     355
     356        bp_activity_delete_meta( $activities[1], 'foo', 'bar' );
     357
     358        $q2 = bp_activity_get( $activity_args );
     359        $this->assertEqualSets( array( $activities[0] ), wp_list_pluck( $q2['activities'], 'id' ) );
     360    }
    275361}
Note: See TracChangeset for help on using the changeset viewer.