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

Unified Diff: lib/filterClasses.js

Issue 29909555: Issue 7046 - Defer caching of domain maps (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Add @private tag Created Oct. 13, 2018, 11:16 p.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/elemHide.js ('k') | test/filterClasses.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/filterClasses.js
===================================================================
--- a/lib/filterClasses.js
+++ b/lib/filterClasses.js
@@ -429,16 +429,24 @@
let oldValue = this._lastHit;
this._lastHit = value;
filterNotifier.emit("filter.lastHit", this, value, oldValue);
}
return this._lastHit;
},
/**
+ * Internal counter to keep track of the number of times the
+ * {@link ActiveFilter#domains} property is accessed.
+ * @type {number}
+ * @private
+ */
+ _domainsAccessCount: 0,
+
+ /**
* String that the domains property should be generated from
* @type {?string}
*/
domainSource: null,
/**
* Separator character used in domainSource property, must be
* overridden by subclasses
@@ -448,16 +456,21 @@
/**
* Map containing domains that this filter should match on/not match
* on or null if the filter should match on all domains
* @type {?Map.<string,boolean>}
*/
get domains()
{
+ // For some filter types this property is accessed only rarely, especially
+ // when the subscriptions are initially loaded. We defer any caching for
+ // such filters.
+ let cacheValue = ++this._domainsAccessCount > 3;
+
let domains = null;
if (this.domainSource)
{
let source = this.domainSource.toLowerCase();
let knownMap = knownDomainMaps.get(source);
if (knownMap)
@@ -498,25 +511,28 @@
domains.set(domain, include);
}
if (domains)
domains.set("", !hasIncludes);
}
- if (domains)
+ if (!domains || cacheValue)
knownDomainMaps.set(source, domains);
}
- this.domainSource = null;
+ if (!domains || cacheValue)
+ this.domainSource = null;
}
- Object.defineProperty(this, "domains", {value: domains});
- return this.domains;
+ if (!domains || cacheValue)
+ Object.defineProperty(this, "domains", {value: domains});
+
+ return domains;
},
/**
* Array containing public keys of websites that this filter should apply to
* @type {?string[]}
*/
sitekeys: null,
« no previous file with comments | « lib/elemHide.js ('k') | test/filterClasses.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld