mirror of https://github.com/zulip/zulip.git
filter: Cache value of can_mark_messages_read.
Given that can_mark_messages_read is called whenever the blue box cursor stops on a message and that it is calculated purely on the basis of sorted_term_types, it makes sense to cache the result.
This commit is contained in:
parent
4d972e1d10
commit
96cd8d3677
|
@ -357,6 +357,25 @@ run_test('can_mark_messages_read', () => {
|
||||||
assert(!filter.can_mark_messages_read());
|
assert(!filter.can_mark_messages_read());
|
||||||
filter = new Filter(in_random_negated);
|
filter = new Filter(in_random_negated);
|
||||||
assert(!filter.can_mark_messages_read());
|
assert(!filter.can_mark_messages_read());
|
||||||
|
|
||||||
|
// test caching of term types
|
||||||
|
// init and stub
|
||||||
|
filter = new Filter(pm_with);
|
||||||
|
filter.stub = filter.calc_can_mark_messages_read;
|
||||||
|
filter.calc_can_mark_messages_read = function () {
|
||||||
|
this.calc_can_mark_messages_read_called = true;
|
||||||
|
return this.stub();
|
||||||
|
};
|
||||||
|
|
||||||
|
// uncached trial
|
||||||
|
filter.calc_can_mark_messages_read_called = false;
|
||||||
|
assert(filter.can_mark_messages_read());
|
||||||
|
assert(filter.calc_can_mark_messages_read_called);
|
||||||
|
|
||||||
|
// cached trial
|
||||||
|
filter.calc_can_mark_messages_read_called = false;
|
||||||
|
assert(filter.can_mark_messages_read());
|
||||||
|
assert(!filter.calc_can_mark_messages_read_called);
|
||||||
});
|
});
|
||||||
|
|
||||||
run_test('show_first_unread', () => {
|
run_test('show_first_unread', () => {
|
||||||
|
|
|
@ -387,7 +387,7 @@ Filter.prototype = {
|
||||||
return this.has_operator('search');
|
return this.has_operator('search');
|
||||||
},
|
},
|
||||||
|
|
||||||
can_mark_messages_read: function () {
|
calc_can_mark_messages_read: function () {
|
||||||
const term_types = this.sorted_term_types();
|
const term_types = this.sorted_term_types();
|
||||||
|
|
||||||
if (_.isEqual(term_types, ['stream', 'topic'])) {
|
if (_.isEqual(term_types, ['stream', 'topic'])) {
|
||||||
|
@ -426,6 +426,13 @@ Filter.prototype = {
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
can_mark_messages_read: function () {
|
||||||
|
if (this._can_mark_messages_read === undefined) {
|
||||||
|
this._can_mark_messages_read = this.calc_can_mark_messages_read();
|
||||||
|
}
|
||||||
|
return this._can_mark_messages_read;
|
||||||
|
},
|
||||||
|
|
||||||
allow_use_first_unread_when_narrowing: function () {
|
allow_use_first_unread_when_narrowing: function () {
|
||||||
return this.can_mark_messages_read() || this.has_operator('is');
|
return this.can_mark_messages_read() || this.has_operator('is');
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue