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

Delta Between Two Patch Sets: lib/filterClasses.js

Issue 29909555: Issue 7046 - Defer caching of domain maps (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Left Patch Set: Use boolean flag instead of counter Created Oct. 15, 2018, 3:28 p.m.
Right 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:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « lib/elemHide.js ('k') | test/filterClasses.js » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 442 matching lines...) Expand 10 before | Expand all | Expand 10 after
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, 460 // For some filter types this property is accessed only rarely,
461 // especially when the subscriptions are initially loaded. We defer any 461 // especially when the subscriptions are initially loaded. We defer any
462 // caching for such filters. 462 // caching for such filters.
463 let cacheValue = this.shouldCacheDomains(); 463 let {cacheDomains} = this;
464 464
465 let source = this.domainSource.toLowerCase(); 465 let source = this.domainSource.toLowerCase();
466 466
467 let knownMap = knownDomainMaps.get(source); 467 let knownMap = knownDomainMaps.get(source);
468 if (knownMap) 468 if (knownMap)
469 { 469 {
470 domains = knownMap; 470 domains = knownMap;
471 } 471 }
472 else 472 else
473 { 473 {
(...skipping 27 matching lines...) Expand all
501 if (!domains) 501 if (!domains)
502 domains = new Map(); 502 domains = new Map();
503 503
504 domains.set(domain, include); 504 domains.set(domain, include);
505 } 505 }
506 506
507 if (domains) 507 if (domains)
508 domains.set("", !hasIncludes); 508 domains.set("", !hasIncludes);
509 } 509 }
510 510
511 if (!domains || cacheValue) 511 if (!domains || cacheDomains)
512 knownDomainMaps.set(source, domains); 512 knownDomainMaps.set(source, domains);
513 } 513 }
514 514
515 if (!domains || cacheValue) 515 if (!domains || cacheDomains)
516 { 516 {
517 this.domainSource = null; 517 this.domainSource = null;
518 Object.defineProperty(this, "domains", {value: domains}); 518 Object.defineProperty(this, "domains", {value: domains});
519 } 519 }
520 } 520 }
521 521
522 return domains; 522 return domains;
523 }, 523 },
524 524
525 /** 525 /**
526 * Whether the value of {@link ActiveFilter#domains} should be cached. This 526 * Whether the value of {@link ActiveFilter#domains} should be cached.
527 * is meant to be overridden by subclasses that don't want the value to be 527 * Defaults to <code>true</code>, but may be overridden by subclasses that
528 * cached (for better memory usage). 528 * don't want the value to be cached (for better memory usage).
529 * @return {boolean} Always <code>true</code>, but may be overriden by 529 * @type {boolean}
530 * subclasses.
531 * @protected 530 * @protected
532 */ 531 */
533 shouldCacheDomains() 532 cacheDomains: true,
534 {
535 return true;
536 },
537 533
538 /** 534 /**
539 * 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
540 * @type {?string[]} 536 * @type {?string[]}
541 */ 537 */
542 sitekeys: null, 538 sitekeys: null,
543 539
544 /** 540 /**
545 * Checks whether this filter is active on a domain. 541 * Checks whether this filter is active on a domain.
546 * @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
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after
856 if (contentType == null) 852 if (contentType == null)
857 ({contentType} = RegExpFilter.prototype); 853 ({contentType} = RegExpFilter.prototype);
858 contentType &= ~type; 854 contentType &= ~type;
859 } 855 }
860 else 856 else
861 { 857 {
862 contentType |= type; 858 contentType |= type;
863 859
864 if (type == RegExpFilter.typeMap.CSP) 860 if (type == RegExpFilter.typeMap.CSP)
865 { 861 {
866 if (!value) 862 if (blocking && !value)
867 return new InvalidFilter(origText, "filter_invalid_csp"); 863 return new InvalidFilter(origText, "filter_invalid_csp");
868 csp = value; 864 csp = value;
869 } 865 }
870 } 866 }
871 } 867 }
872 else 868 else
873 { 869 {
874 switch (option.toLowerCase()) 870 switch (option.toLowerCase())
875 { 871 {
876 case "match-case": 872 case "match-case":
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
1168 * @augments ContentFilter 1164 * @augments ContentFilter
1169 */ 1165 */
1170 function ElemHideBase(text, domains, selector) 1166 function ElemHideBase(text, domains, selector)
1171 { 1167 {
1172 ContentFilter.call(this, text, domains, selector); 1168 ContentFilter.call(this, text, domains, selector);
1173 } 1169 }
1174 exports.ElemHideBase = ElemHideBase; 1170 exports.ElemHideBase = ElemHideBase;
1175 1171
1176 ElemHideBase.prototype = extend(ContentFilter, { 1172 ElemHideBase.prototype = extend(ContentFilter, {
1177 /** 1173 /**
1178 * Whether {@link ActiveFilter#domains} has been accessed at least once. 1174 * @see ActiveFilter#domains
1179 * @type {boolean} 1175 * @type {?Map.<string,boolean>}
1180 * @private
1181 */
1182 _domainsAccessed: false,
1183
1184 /**
1185 * See ActiveFilter.domains
1186 * @inheritdoc
1187 */ 1176 */
1188 get domains() 1177 get domains()
1189 { 1178 {
1190 let {get} = Object.getOwnPropertyDescriptor(ActiveFilter.prototype, 1179 let {get} = Object.getOwnPropertyDescriptor(ActiveFilter.prototype,
1191 "domains"); 1180 "domains");
1192 let value = get.call(this); 1181 let value = get.call(this);
1193 this._domainsAccessed = true; 1182 this.cacheDomains = true;
1194 return value; 1183 return value;
1195 }, 1184 },
1196 1185
1197 /** 1186 /**
1198 * See ActiveFilter.shouldCacheDomains() 1187 * Initially <code>false</code>, but set to <code>true</code> after
1199 * @inheritdoc 1188 * {@link ActiveFilter#domains} has been accessed once.
1200 */ 1189 * @see ActiveFilter#cacheDomains
1201 shouldCacheDomains() 1190 * @type {boolean}
1202 { 1191 * @protected
1203 return this._domainsAccessed; 1192 */
1204 }, 1193 cacheDomains: false,
1205 1194
1206 /** 1195 /**
1207 * CSS selector for the HTML elements that should be hidden 1196 * CSS selector for the HTML elements that should be hidden
1208 * @type {string} 1197 * @type {string}
1209 */ 1198 */
1210 get selector() 1199 get selector()
1211 { 1200 {
1212 // Braces are being escaped to prevent CSS rule injection. 1201 // Braces are being escaped to prevent CSS rule injection.
1213 return this.body.replace("{", "\\7B ").replace("}", "\\7D "); 1202 return this.body.replace("{", "\\7B ").replace("}", "\\7D ");
1214 } 1203 }
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
1287 1276
1288 /** 1277 /**
1289 * Script that should be executed 1278 * Script that should be executed
1290 * @type {string} 1279 * @type {string}
1291 */ 1280 */
1292 get script() 1281 get script()
1293 { 1282 {
1294 return this.body; 1283 return this.body;
1295 } 1284 }
1296 }); 1285 });
LEFTRIGHT

Powered by Google App Engine
This is Rietveld