mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-03 21:43:21 +00:00 
			
		
		
		
	muting: Fix calling update_unread_counts in a loop.
Previously, set_muted_topics was calling update_unread_counts once for each topic in the input; this results in poor performance when there is a large number of muted topics. Fixes: #3605
This commit is contained in:
		@@ -55,6 +55,36 @@ var muting = require('js/muting.js');
 | 
			
		||||
    ]);
 | 
			
		||||
}());
 | 
			
		||||
 | 
			
		||||
(function test_muting_performance() {
 | 
			
		||||
    // This test ensures that each call to mute_topic and set_muted_topics only
 | 
			
		||||
    // results in one call to unread.update_unread_counts.
 | 
			
		||||
 | 
			
		||||
    // We replace (for the duration of this test) the real update_unread_counts
 | 
			
		||||
    // with a test version that just counts the number of calls.
 | 
			
		||||
    var saved = unread.update_unread_counts;
 | 
			
		||||
    var num_calls = 0;
 | 
			
		||||
    unread.update_unread_counts = function () {
 | 
			
		||||
        num_calls += 1;
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    muting.mute_topic('office', 'gossip');
 | 
			
		||||
    assert.equal(num_calls, 1);
 | 
			
		||||
 | 
			
		||||
    muting.set_muted_topics([
 | 
			
		||||
        ['social', 'breakfast'],
 | 
			
		||||
    ]);
 | 
			
		||||
    assert.equal(num_calls, 2);
 | 
			
		||||
 | 
			
		||||
    muting.set_muted_topics([
 | 
			
		||||
        ['social', 'breakfast'],
 | 
			
		||||
        ['design', 'typography'],
 | 
			
		||||
        ['devel', 'java'],
 | 
			
		||||
    ]);
 | 
			
		||||
    assert.equal(num_calls, 3);
 | 
			
		||||
 | 
			
		||||
    unread.update_unread_counts = saved;
 | 
			
		||||
}());
 | 
			
		||||
 | 
			
		||||
(function test_case_insensitivity() {
 | 
			
		||||
    muting.set_muted_topics([]);
 | 
			
		||||
    assert(!muting.is_topic_muted('SOCial', 'breakfast'));
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user