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

Unified 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: Fix typo Created Nov. 18, 2018, 12:50 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/filterListener.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/filterStorage.js
===================================================================
--- a/lib/filterStorage.js
+++ b/lib/filterStorage.js
@@ -123,16 +123,43 @@
* @type {number}
*/
get subscriptionCount()
{
return this.knownSubscriptions.size;
}
/**
+ * Yields subscriptions in the storage to which the given filter belongs.
+ * @param {Filter} filter
+ * @yields {Subscription}
+ */
+ *subscriptionsForFilter(filter)
+ {
+ if (!filter.subscriptionsAdded)
+ addSubscriptionsToFilter(filter);
+
+ yield* filter.subscriptions();
+ }
+
+ /**
+ * Returns the number of subscriptions in the storage to which the given
+ * filter belongs.
+ * @param {Filter} filter
+ * @return {number}
+ */
+ getSubscriptionCountForFilter(filter)
+ {
+ if (!filter.subscriptionsAdded)
+ addSubscriptionsToFilter(filter);
+
+ return filter.subscriptionCount;
+ }
+
+ /**
* Finds the filter group that a filter should be added to by default. Will
* return <code>null</code> if this group doesn't exist yet.
* @param {Filter} filter
* @returns {?SpecialSubscription}
*/
getGroupForFilter(filter)
{
let generalSubscription = null;
@@ -646,16 +673,32 @@
* Reads the user's filters from disk, manages them in memory, and writes them
* back to disk.
*/
let filterStorage = new FilterStorage();
exports.filterStorage = filterStorage;
/**
+ * Adds to a filter any subscriptions in the storage to which the filter
+ * belongs.
+ * @param {Filter} filter
+ */
+function addSubscriptionsToFilter(filter)
+{
+ for (let subscription of filterStorage.subscriptions())
+ {
+ if (subscription.hasFilter(filter))
+ filter.addSubscription(subscription);
+ }
+
+ filter.subscriptionsAdded = true;
+}
+
+/**
* Connects a subscription to its filters without any notifications.
* @param {Subscription} subscription The subscription that should be
* connected to its filters.
* @param {?Array.<Filter>} [filters] A list of filters to which the
* subscription should be connected. If this is not given, the subscription
* is connected to its own filters.
*/
function connectSubscriptionFilters(subscription, filters)
« no previous file with comments | « lib/filterListener.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld