Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: lib/filterStorage.js

Issue 29860589: Issue 6829 - Free filters when subscriptions are empty (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Created Aug. 21, 2018, 9:44 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-present eyeo GmbH 3 * Copyright (C) 2006-present eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 * Removes a filter subscription from the list 138 * Removes a filter subscription from the list
139 * @param {Subscription} subscription filter subscription to be removed 139 * @param {Subscription} subscription filter subscription to be removed
140 */ 140 */
141 removeSubscription(subscription) 141 removeSubscription(subscription)
142 { 142 {
143 for (let i = 0; i < FilterStorage.subscriptions.length; i++) 143 for (let i = 0; i < FilterStorage.subscriptions.length; i++)
144 { 144 {
145 if (FilterStorage.subscriptions[i].url == subscription.url) 145 if (FilterStorage.subscriptions[i].url == subscription.url)
146 { 146 {
147 removeSubscriptionFilters(subscription); 147 removeSubscriptionFilters(subscription);
148 148
Manish Jethani 2018/08/25 15:03:38 We should delete the filters here.
Jon Sonesen 2018/08/27 16:28:03 Hm, because of the update function calling removSu
149 FilterStorage.subscriptions.splice(i--, 1); 149 FilterStorage.subscriptions.splice(i--, 1);
150 FilterStorage.knownSubscriptions.delete(subscription.url); 150 FilterStorage.knownSubscriptions.delete(subscription.url);
151 151
152 // This should be the last remaining reference to the Subscription 152 // This should be the last remaining reference to the Subscription
153 // object. 153 // object.
154 Subscription.knownSubscriptions.delete(subscription.url); 154 Subscription.knownSubscriptions.delete(subscription.url);
155 155
156 FilterNotifier.triggerListeners("subscription.removed", subscription); 156 FilterNotifier.triggerListeners("subscription.removed", subscription);
157 return; 157 return;
158 } 158 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 /** 191 /**
192 * Replaces the list of filters in a subscription by a new list 192 * Replaces the list of filters in a subscription by a new list
193 * @param {Subscription} subscription filter subscription to be updated 193 * @param {Subscription} subscription filter subscription to be updated
194 * @param {Filter[]} filters new filter list 194 * @param {Filter[]} filters new filter list
195 */ 195 */
196 updateSubscriptionFilters(subscription, filters) 196 updateSubscriptionFilters(subscription, filters)
197 { 197 {
198 removeSubscriptionFilters(subscription); 198 removeSubscriptionFilters(subscription);
199 subscription.oldFilters = subscription.filters; 199 subscription.oldFilters = subscription.filters;
200 subscription.filters = filters; 200 subscription.filters = filters;
201 addSubscriptionFilters(subscription); 201 addSubscriptionFilters(subscription);
Manish Jethani 2018/08/25 15:03:38 After calling addSubscriptionFilters, we should de
Jon Sonesen 2018/08/27 16:28:02 See comment above
202 FilterNotifier.triggerListeners("subscription.updated", subscription); 202 FilterNotifier.triggerListeners("subscription.updated", subscription);
203 delete subscription.oldFilters; 203 delete subscription.oldFilters;
204 }, 204 },
205 205
206 /** 206 /**
207 * Adds a user-defined filter to the list 207 * Adds a user-defined filter to the list
208 * @param {Filter} filter 208 * @param {Filter} filter
209 * @param {SpecialSubscription} [subscription] 209 * @param {SpecialSubscription} [subscription]
210 * particular group that the filter should be added to 210 * particular group that the filter should be added to
211 * @param {number} [position] 211 * @param {number} [position]
(...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after
671 * Removes subscription's filters from the subscription without any 671 * Removes subscription's filters from the subscription without any
672 * notifications. 672 * notifications.
673 * @param {Subscription} subscription filter subscription to be removed 673 * @param {Subscription} subscription filter subscription to be removed
674 */ 674 */
675 function removeSubscriptionFilters(subscription) 675 function removeSubscriptionFilters(subscription)
676 { 676 {
677 if (!FilterStorage.knownSubscriptions.has(subscription.url)) 677 if (!FilterStorage.knownSubscriptions.has(subscription.url))
678 return; 678 return;
679 679
680 for (let filter of subscription.filters) 680 for (let filter of subscription.filters)
681 {
681 filter.subscriptions.delete(subscription); 682 filter.subscriptions.delete(subscription);
683 if (filter.subscriptions.size == 0)
Manish Jethani 2018/08/25 15:03:38 removeSubscriptionFilters is also called from upda
jsonesen 2018/08/25 15:18:46 The deletion should I ly occur if there are no sub
jsonesen 2018/08/25 15:32:08 Oh shoot nevermind, since it removes first then ad
Manish Jethani 2018/08/26 15:56:19 Yes, exactly. If a filter is also in a different s
684 Filter.knownFilters.delete(filter.text);
Jon Sonesen 2018/08/21 21:50:41 I found that there is a pretty good reduction in t
685 }
682 } 686 }
683 687
684 /** 688 /**
685 * Listener returned by FilterStorage.importData(), parses filter data. 689 * Listener returned by FilterStorage.importData(), parses filter data.
686 * @constructor 690 * @constructor
687 */ 691 */
688 function INIParser() 692 function INIParser()
689 { 693 {
690 this.fileProperties = this.curObj = {}; 694 this.fileProperties = this.curObj = {};
691 this.subscriptions = []; 695 this.subscriptions = [];
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
771 else if (this.wantObj === false && val) 775 else if (this.wantObj === false && val)
772 this.curObj.push(val.replace(/\\\[/g, "[")); 776 this.curObj.push(val.replace(/\\\[/g, "["));
773 } 777 }
774 finally 778 finally
775 { 779 {
776 Filter.knownFilters = origKnownFilters; 780 Filter.knownFilters = origKnownFilters;
777 Subscription.knownSubscriptions = origKnownSubscriptions; 781 Subscription.knownSubscriptions = origKnownSubscriptions;
778 } 782 }
779 } 783 }
780 }; 784 };
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld