Update subscription text directly
Background
In https://issues.adblockplus.org/ticket/7029 we lost the subscriptions
property of the Filter
object; this means now we must look up the subscriptions for a filter every time there is an update to the subscription. But this does not have to be done for every filter, only for filters that have been added or removed.
We can add an updateFilterText()
method to the Subscription
object (internal use only). It can take the text and return the delta from the previous text (added and removed filters). We could then use this delta to call addFilter()
and removeFilter()
for added and removed filters respectively.
This change would reduce the time spent in updateSubscriptionFilters()
for EasyList by ~60%.
What to change
See !50 (closed) for implementation.
Integration notes
The subscription.updated
event now comes with the delta of the old and the new subscription text. Where a handler for the event would previously look like (subscription, oldSubscriptionText) => { ... }
, now it should look like (subscription, textDelta) => { ... }
; the textDelta
argument will be an object containing two properties, added
and removed
, each being an array of added and removed filter text respectively.
No changes are required to eyeo/adblockplus/abpui/adblockplusui>, while eyeo/adblockplus/adblockpluschrome> should be updated to handle the subscription.updated
event correctly (in lib/requestBlocker.js
).
Hints for testers
Use the following HTML:
<!DOCTYPE html>
<html>
<body>
<div class="foo">foo</div>
<div class="bar">bar</div>
<div class="lambda">lambda</div>
</body>
</html>
Now add an external subscription, let's say hosted on https://example.com/subscription.txt
, containing the following filters:
##.foo
##.bar
Reload the page and see that foo
and bar
are hidden but lambda
is visible.
Now add one more filter to the subscription and sync manually:
##.lambda
Reload the page and see that now all three of foo
, bar
, and lambda
are hidden.
Remove the filter ##.bar
, sync, reload the page, and see that now foo
and lambda
are hidden but bar
is visible.
Add two instances of the filter ##.bar
(repeat the line once) and remove the filter ##.foo
, sync, reload the page, and see that now foo
is visible but bar
and lambda
are hidden.
Remove one of the instances of ##.bar
, sync, reload the page, and see that foo
is still visible but bar
and lambda
are still hidden.