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

Side by Side Diff: lib/filterClasses.js

Issue 29909555: Issue 7046 - Defer caching of domain maps (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Change shouldCacheDomain function to cacheDomain property Created Oct. 16, 2018, 6 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 | « lib/elemHide.js ('k') | test/filterClasses.js » ('j') | 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 439 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 * Map containing domains that this filter should match on/not match 450 * Map containing domains that this filter should match on/not match
451 * on or null if the filter should match on all domains 451 * on or null if the filter should match on all domains
452 * @type {?Map.<string,boolean>} 452 * @type {?Map.<string,boolean>}
453 */ 453 */
454 get domains() 454 get domains()
455 { 455 {
456 let domains = null; 456 let domains = null;
457 457
458 if (this.domainSource) 458 if (this.domainSource)
459 { 459 {
460 // For some filter types this property is accessed only rarely,
461 // especially when the subscriptions are initially loaded. We defer any
462 // caching for such filters.
463 let {cacheDomains} = this;
464
460 let source = this.domainSource.toLowerCase(); 465 let source = this.domainSource.toLowerCase();
461 466
462 let knownMap = knownDomainMaps.get(source); 467 let knownMap = knownDomainMaps.get(source);
463 if (knownMap) 468 if (knownMap)
464 { 469 {
465 domains = knownMap; 470 domains = knownMap;
466 } 471 }
467 else 472 else
468 { 473 {
469 let list = source.split(this.domainSeparator); 474 let list = source.split(this.domainSeparator);
(...skipping 26 matching lines...) Expand all
496 if (!domains) 501 if (!domains)
497 domains = new Map(); 502 domains = new Map();
498 503
499 domains.set(domain, include); 504 domains.set(domain, include);
500 } 505 }
501 506
502 if (domains) 507 if (domains)
503 domains.set("", !hasIncludes); 508 domains.set("", !hasIncludes);
504 } 509 }
505 510
506 if (domains) 511 if (!domains || cacheDomains)
507 knownDomainMaps.set(source, domains); 512 knownDomainMaps.set(source, domains);
508 } 513 }
509 514
510 this.domainSource = null; 515 if (!domains || cacheDomains)
516 {
517 this.domainSource = null;
518 Object.defineProperty(this, "domains", {value: domains});
519 }
511 } 520 }
512 521
513 Object.defineProperty(this, "domains", {value: domains}); 522 return domains;
514 return this.domains;
515 }, 523 },
516 524
517 /** 525 /**
526 * Whether the value of {@link ActiveFilter#domains} should be cached.
527 * Defaults to <code>true</code>, but may be overridden by subclasses that
528 * don't want the value to be cached (for better memory usage).
529 * @type {boolean}
530 * @protected
531 */
532 cacheDomains: true,
533
534 /**
518 * Array containing public keys of websites that this filter should apply to 535 * Array containing public keys of websites that this filter should apply to
519 * @type {?string[]} 536 * @type {?string[]}
520 */ 537 */
521 sitekeys: null, 538 sitekeys: null,
522 539
523 /** 540 /**
524 * Checks whether this filter is active on a domain. 541 * Checks whether this filter is active on a domain.
525 * @param {string} [docDomain] domain name of the document that loads the URL 542 * @param {string} [docDomain] domain name of the document that loads the URL
526 * @param {string} [sitekey] public key provided by the document 543 * @param {string} [sitekey] public key provided by the document
527 * @return {boolean} true in case of the filter being active 544 * @return {boolean} true in case of the filter being active
(...skipping 619 matching lines...) Expand 10 before | Expand all | Expand 10 after
1147 * @augments ContentFilter 1164 * @augments ContentFilter
1148 */ 1165 */
1149 function ElemHideBase(text, domains, selector) 1166 function ElemHideBase(text, domains, selector)
1150 { 1167 {
1151 ContentFilter.call(this, text, domains, selector); 1168 ContentFilter.call(this, text, domains, selector);
1152 } 1169 }
1153 exports.ElemHideBase = ElemHideBase; 1170 exports.ElemHideBase = ElemHideBase;
1154 1171
1155 ElemHideBase.prototype = extend(ContentFilter, { 1172 ElemHideBase.prototype = extend(ContentFilter, {
1156 /** 1173 /**
1174 * @see ActiveFilter#domains
1175 * @type {?Map.<string,boolean>}
1176 */
1177 get domains()
1178 {
1179 let {get} = Object.getOwnPropertyDescriptor(ActiveFilter.prototype,
1180 "domains");
1181 let value = get.call(this);
1182 this.cacheDomains = true;
1183 return value;
1184 },
1185
1186 /**
1187 * Initially <code>false</code>, but set to <code>true</code> after
1188 * {@link ActiveFilter#domains} has been accessed once.
1189 * @see ActiveFilter#cacheDomains
1190 * @type {boolean}
1191 * @protected
1192 */
1193 cacheDomains: false,
1194
1195 /**
1157 * CSS selector for the HTML elements that should be hidden 1196 * CSS selector for the HTML elements that should be hidden
1158 * @type {string} 1197 * @type {string}
1159 */ 1198 */
1160 get selector() 1199 get selector()
1161 { 1200 {
1162 // Braces are being escaped to prevent CSS rule injection. 1201 // Braces are being escaped to prevent CSS rule injection.
1163 return this.body.replace("{", "\\7B ").replace("}", "\\7D "); 1202 return this.body.replace("{", "\\7B ").replace("}", "\\7D ");
1164 } 1203 }
1165 }); 1204 });
1166 1205
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
1237 1276
1238 /** 1277 /**
1239 * Script that should be executed 1278 * Script that should be executed
1240 * @type {string} 1279 * @type {string}
1241 */ 1280 */
1242 get script() 1281 get script()
1243 { 1282 {
1244 return this.body; 1283 return this.body;
1245 } 1284 }
1246 }); 1285 });
OLDNEW
« 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