unread: Convert ids.push(...a) to a loop.

Calling a function with hundreds of thousands to millions of
arguments, depending on the browser, can throw a RangeError.  This was
true of both ids.push(...a) and the [].concat.apply construction that
it replaced in commit 59d55d1e06,
although the old one was less likely to overflow due to bucketing.
Use a loop instead.

Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
This commit is contained in:
Anders Kaseorg 2020-02-26 00:08:35 -08:00 committed by Tim Abbott
parent 7822964f28
commit 56c03e1311
1 changed files with 7 additions and 3 deletions

View File

@ -159,7 +159,9 @@ exports.unread_pm_counter = (function () {
const ids = []; const ids = [];
for (const id_set of bucketer.values()) { for (const id_set of bucketer.values()) {
ids.push(...Array.from(id_set)); for (const id of id_set) {
ids.push(id);
}
} }
return util.sorted_ids(ids); return util.sorted_ids(ids);
@ -331,9 +333,11 @@ exports.unread_topic_counter = (function () {
const ids = []; const ids = [];
const sub = stream_data.get_sub_by_id(stream_id); const sub = stream_data.get_sub_by_id(stream_id);
for (const [topic, msgs] of per_stream_bucketer) { for (const [topic, id_set] of per_stream_bucketer) {
if (sub && !muting.is_topic_muted(stream_id, topic)) { if (sub && !muting.is_topic_muted(stream_id, topic)) {
ids.push(...Array.from(msgs)); for (const id of id_set) {
ids.push(id);
}
} }
} }