Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
filter: Cached computed values for faster comparison.
Aman Agrawala7b86a7e663e
diff --git a/web/src/filter.ts b/web/src/filter.tsindex 90e66c5fe28..ffb569879aa 100644--- a/web/src/filter.ts+++ b/web/src/filter.ts@@ -297,6 +297,7 @@ export class Filter {_can_mark_messages_read?: boolean;requires_adjustment_for_moved_with_target?: boolean;narrow_requires_hash_change: boolean;+ cached_sorted_terms_for_comparison?: string[] | undefined = undefined;constructor(terms: NarrowTerm[]) {this._terms = terms;@@ -871,6 +872,7 @@ export class Filter {setup_filter(terms: NarrowTerm[]): void {this._terms = this.fix_terms(terms);+ this.cached_sorted_terms_for_comparison = undefined;if (this.has_operator("channel")) {this._sub = stream_data.get_sub_by_name(this.operands("channel")[0]!);}@@ -884,6 +886,10 @@ export class Filter {}sorted_terms_for_comparison(excluded_operators?: string[]): string[] {+ if (!excluded_operators && this.cached_sorted_terms_for_comparison !== undefined) {+ return this.cached_sorted_terms_for_comparison;+ }+let filter_terms = this._terms;if (excluded_operators) {filter_terms = this._terms.filter(@@ -902,6 +908,10 @@ export class Filter {}).sort(util.strcmp);+ if (!excluded_operators) {+ this.cached_sorted_terms_for_comparison = sorted_simplified_terms;+ }+return sorted_simplified_terms;}