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

Side by Side Diff: lib/filterStorage.js

Issue 29935568: Issue 7096 - Make it possible to lazy initialize a filter's subscriptions (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Rebase and refactor Created Nov. 18, 2018, 12:46 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« lib/filterClasses.js ('K') | « lib/filterListener.js ('k') | 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 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 /** 121 /**
122 * The number of subscriptions in the storage. 122 * The number of subscriptions in the storage.
123 * @type {number} 123 * @type {number}
124 */ 124 */
125 get subscriptionCount() 125 get subscriptionCount()
126 { 126 {
127 return this.knownSubscriptions.size; 127 return this.knownSubscriptions.size;
128 } 128 }
129 129
130 /** 130 /**
131 * Yields subscriptions in the storage to which the given filter belongs.
132 * @param {Filter} filter
133 * @yields {Subscription}
134 */
135 *subscriptionsForFilter(filter)
136 {
137 if (!filter.subscriptionsAdded)
138 addSubscriptionsToFilter(filter);
139
140 yield* filter.subscriptions();
141 }
142
143 /**
144 * Returns the number of subscriptions in the storage to which the given
145 * filter belongs.
146 * @param {Filter} filter
147 * @return {number}
148 */
149 getSubscriptionCountForFilter(filter)
150 {
151 if (!filter.subscriptionsAdded)
152 addSubscriptionsToFilter(filter);
153
154 return filter.subscriptionCount;
155 }
156
157 /**
131 * Finds the filter group that a filter should be added to by default. Will 158 * Finds the filter group that a filter should be added to by default. Will
132 * return <code>null</code> if this group doesn't exist yet. 159 * return <code>null</code> if this group doesn't exist yet.
133 * @param {Filter} filter 160 * @param {Filter} filter
134 * @returns {?SpecialSubscription} 161 * @returns {?SpecialSubscription}
135 */ 162 */
136 getGroupForFilter(filter) 163 getGroupForFilter(filter)
137 { 164 {
138 let generalSubscription = null; 165 let generalSubscription = null;
139 for (let subscription of this.knownSubscriptions.values()) 166 for (let subscription of this.knownSubscriptions.values())
140 { 167 {
(...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after
644 671
645 /** 672 /**
646 * Reads the user's filters from disk, manages them in memory, and writes them 673 * Reads the user's filters from disk, manages them in memory, and writes them
647 * back to disk. 674 * back to disk.
648 */ 675 */
649 let filterStorage = new FilterStorage(); 676 let filterStorage = new FilterStorage();
650 677
651 exports.filterStorage = filterStorage; 678 exports.filterStorage = filterStorage;
652 679
653 /** 680 /**
681 * Adds to the filter any subscriptions in the storage to which a filter
682 * belongs.
683 * @param {Filter} filter
684 */
685 function addSubscriptionsToFilter(filter)
686 {
687 for (let subscription of filterStorage.subscriptions())
688 {
689 if (subscription.hasFilter(filter))
690 filter.addSubscription(subscription);
691 }
692
693 filter.subscriptionsAdded = true;
694 }
695
696 /**
654 * Connects a subscription to its filters without any notifications. 697 * Connects a subscription to its filters without any notifications.
655 * @param {Subscription} subscription The subscription that should be 698 * @param {Subscription} subscription The subscription that should be
656 * connected to its filters. 699 * connected to its filters.
657 * @param {?Array.<Filter>} [filters] A list of filters to which the 700 * @param {?Array.<Filter>} [filters] A list of filters to which the
658 * subscription should be connected. If this is not given, the subscription 701 * subscription should be connected. If this is not given, the subscription
659 * is connected to its own filters. 702 * is connected to its own filters.
660 */ 703 */
661 function connectSubscriptionFilters(subscription, filters) 704 function connectSubscriptionFilters(subscription, filters)
662 { 705 {
663 if (!filterStorage.knownSubscriptions.has(subscription.url)) 706 if (!filterStorage.knownSubscriptions.has(subscription.url))
(...skipping 12 matching lines...) Expand all
676 * subscription is disconnected from its own filters. 719 * subscription is disconnected from its own filters.
677 */ 720 */
678 function disconnectSubscriptionFilters(subscription, filters) 721 function disconnectSubscriptionFilters(subscription, filters)
679 { 722 {
680 if (!filterStorage.knownSubscriptions.has(subscription.url)) 723 if (!filterStorage.knownSubscriptions.has(subscription.url))
681 return; 724 return;
682 725
683 for (let filter of filters || subscription.filters()) 726 for (let filter of filters || subscription.filters())
684 filter.removeSubscription(subscription); 727 filter.removeSubscription(subscription);
685 } 728 }
OLDNEW
« lib/filterClasses.js ('K') | « lib/filterListener.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld