Skip to:
Content

BuddyPress.org

Changeset 9714


Ignore:
Timestamp:
04/07/2015 01:18:51 AM (6 years ago)
Author:
r-a-y
Message:

Messages: Bust recipient cache when a message thread is marked as read or unread.

See r9482, which introduces message recipient caching.

Fixes #6220.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-messages/classes/class-bp_messages-thread.php

    r9486 r9714  
    509509        $wpdb->query($sql);
    510510
     511        wp_cache_delete( 'thread_recipients_' . $thread_id, 'bp_messages' );
    511512        wp_cache_delete( bp_loggedin_user_id(), 'bp_messages_unread_count' );
    512513    }
     
    526527        $wpdb->query($sql);
    527528
     529        wp_cache_delete( 'thread_recipients_' . $thread_id, 'bp_messages' );
    528530        wp_cache_delete( bp_loggedin_user_id(), 'bp_messages_unread_count' );
    529531    }
  • trunk/tests/phpunit/testcases/messages/class.bp-messages-thread.php

    r9482 r9714  
    217217        $this->assertFalse( wp_cache_get( 'thread_recipients_' . $t1, 'bp_messages' ) );
    218218    }
     219
     220    /**
     221     * @group get_recipients
     222     * @group cache
     223     */
     224    public function test_get_recipients_cache_should_be_busted_when_thread_is_read() {
     225        global $wpdb;
     226
     227        $u1 = $this->factory->user->create();
     228        $u2 = $this->factory->user->create();
     229
     230        $t1 = $this->factory->message->create( array(
     231            'sender_id' => $u1,
     232            'recipients' => array( $u2 ),
     233            'subject' => 'Foo',
     234        ) );
     235
     236        $thread = new BP_Messages_Thread( $t1 );
     237        $recipients = $thread->get_recipients();
     238
     239        // Verify that the cache is populated.
     240        $num_queries = $wpdb->num_queries;
     241        $recipients_cached = $thread->get_recipients();
     242        $this->assertEquals( $num_queries, $wpdb->num_queries );
     243
     244        // Mark thread as read
     245        $current_user = get_current_user_id();
     246        $this->set_current_user( $u2 );
     247        messages_mark_thread_read( $t1 );
     248
     249        // Cache should be empty.
     250        $this->assertFalse( wp_cache_get( 'thread_recipients_' . $t1, 'bp_messages' ) );
     251
     252        $this->set_current_user( $current_user );
     253    }
     254
     255    /**
     256     * @group get_recipients
     257     * @group cache
     258     */
     259    public function test_get_recipients_cache_should_be_busted_when_thread_is_unread() {
     260        global $wpdb;
     261
     262        $u1 = $this->factory->user->create();
     263        $u2 = $this->factory->user->create();
     264
     265        $t1 = $this->factory->message->create( array(
     266            'sender_id' => $u1,
     267            'recipients' => array( $u2 ),
     268            'subject' => 'Foo',
     269        ) );
     270
     271        $thread = new BP_Messages_Thread( $t1 );
     272        $recipients = $thread->get_recipients();
     273
     274        // Verify that the cache is populated.
     275        $num_queries = $wpdb->num_queries;
     276        $recipients_cached = $thread->get_recipients();
     277        $this->assertEquals( $num_queries, $wpdb->num_queries );
     278
     279        // Mark thread as unread
     280        $current_user = get_current_user_id();
     281        $this->set_current_user( $u2 );
     282        messages_mark_thread_unread( $t1 );
     283
     284        // Cache should be empty.
     285        $this->assertFalse( wp_cache_get( 'thread_recipients_' . $t1, 'bp_messages' ) );
     286
     287        $this->set_current_user( $current_user );
     288    }
    219289}
Note: See TracChangeset for help on using the changeset viewer.