mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-03 21:43:21 +00:00 
			
		
		
		
	Simplify unread_topic_count.update().
The prior implementation was needlessly complex. Both del() and add() are cheap and idempotent. With this change we no longer bother to delete a topic from a dictionary when its last message is mark as read, since it doesn't really help performance. We add a line to the tests to maintain 100% line coverage.
This commit is contained in:
		@@ -104,6 +104,7 @@ var zero_counts = {
 | 
			
		||||
    assert.equal(count, 2);
 | 
			
		||||
    assert(unread.topic_has_any_unread(stream_id, 'lunch'));
 | 
			
		||||
    assert(!unread.topic_has_any_unread(wrong_stream_id, 'lunch'));
 | 
			
		||||
    assert(!unread.topic_has_any_unread(stream_id, 'NOT lunch'));
 | 
			
		||||
 | 
			
		||||
    var event = {
 | 
			
		||||
        subject: 'dinner',
 | 
			
		||||
 
 | 
			
		||||
@@ -83,17 +83,8 @@ exports.unread_topic_counter = (function () {
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    self.update = function (stream_id, topic, new_topic, msg_id) {
 | 
			
		||||
        if (unread_topics.has(stream_id) &&
 | 
			
		||||
            unread_topics.get(stream_id).has(topic) &&
 | 
			
		||||
            unread_topics.get(stream_id).get(topic).get(msg_id)) {
 | 
			
		||||
            // Move the unread topic count to the new topic
 | 
			
		||||
            unread_topics.get(stream_id).get(topic).del(msg_id);
 | 
			
		||||
            if (unread_topics.get(stream_id).get(topic).num_items() === 0) {
 | 
			
		||||
                unread_topics.get(stream_id).del(topic);
 | 
			
		||||
            }
 | 
			
		||||
            unread_topics.get(stream_id).setdefault(new_topic, num_dict());
 | 
			
		||||
            unread_topics.get(stream_id).get(new_topic).set(msg_id, true);
 | 
			
		||||
        }
 | 
			
		||||
        self.del(stream_id, topic, msg_id);
 | 
			
		||||
        self.add(stream_id, new_topic, msg_id);
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    self.add = function (stream_id, topic, msg_id) {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user