RCFilters: Don't apply/clear highlights 66 times
authorRoan Kattouw <roan.kattouw@gmail.com>
Sat, 30 Sep 2017 00:35:43 +0000 (17:35 -0700)
committerRoan Kattouw <roan.kattouw@gmail.com>
Sat, 30 Sep 2017 00:35:43 +0000 (17:35 -0700)
commit212d67c67e153f95fd2eb49a75b7ece27d794b53
tree91d71ea36b5820405265217f348204634a1a9cef
parent8ccb891d18011a65a9b6040b750af8a7f3a7f126
RCFilters: Don't apply/clear highlights 66 times

Applying highlights on init was very slow, because applyHighlights
was called 66 times and clearHighlights 64 times.

We first call toggleHighlight() on each filter item, which
leads to update events being emitted by each item, and onItemUpdate
calls clearHighlights() followed by applyHighlights().
There are 64 filter items in my setup, so that's 64 pairs of
clear+apply calls. Then we emit highlightChange, which causes
another apply call, and onModelUpdate calls apply as well.

This change makes sure that the model-wide ("global") highlight
flag is always set to false while we're toggling the highlight
flags on the individual items, so that onItemUpdate short-circuits
and doesn't call clear/apply. There are still other issues (too many
places call clear/apply, too many events emitted), but running the
highlight code twice instead of 130 times on init fixes most
of the performance problems.

Bug: T177107
Change-Id: I65c409ccfabd974ef0b5e2bddff70c9e78e8fd60
resources/src/mediawiki.rcfilters/dm/mw.rcfilters.dm.FiltersViewModel.js