fix regression in per-list filter counts (reported by @mapx-)

This commit is contained in:
Raymond Hill 2017-12-29 13:31:37 -05:00
parent 707d7708a1
commit 5c20182948
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
4 changed files with 68 additions and 7 deletions

View File

@ -30,6 +30,8 @@
filterDB = new µb.staticExtFilteringEngine.HostnameBasedDB(), filterDB = new µb.staticExtFilteringEngine.HostnameBasedDB(),
pselectors = new Map(), pselectors = new Map(),
duplicates = new Set(), duplicates = new Set(),
acceptedCount = 0,
discardedCount = 0,
docRegister, loggerRegister; docRegister, loggerRegister;
var PSelectorHasTask = function(task) { var PSelectorHasTask = function(task) {
@ -224,6 +226,8 @@
filterDB.clear(); filterDB.clear();
pselectors.clear(); pselectors.clear();
duplicates.clear(); duplicates.clear();
acceptedCount = 0;
discardedCount = 0;
}; };
api.freeze = function() { api.freeze = function() {
@ -260,8 +264,12 @@
reader.select(1002); reader.select(1002);
while ( reader.next() ) { while ( reader.next() ) {
acceptedCount += 1;
var fingerprint = reader.fingerprint(); var fingerprint = reader.fingerprint();
if ( duplicates.has(fingerprint) ) { continue; } if ( duplicates.has(fingerprint) ) {
discardedCount += 1;
continue;
}
duplicates.add(fingerprint); duplicates.add(fingerprint);
var args = reader.args(); var args = reader.args();
filterDB.add(args[1], { filterDB.add(args[1], {
@ -374,6 +382,19 @@
} }
}; };
Object.defineProperties(api, {
acceptedCount: {
get: function() {
return acceptedCount;
}
},
discardedCount: {
get: function() {
return discardedCount;
}
}
});
return api; return api;
})(); })();

View File

@ -29,6 +29,8 @@
var µb = µBlock, var µb = µBlock,
scriptletDB = new µb.staticExtFilteringEngine.HostnameBasedDB(), scriptletDB = new µb.staticExtFilteringEngine.HostnameBasedDB(),
duplicates = new Set(), duplicates = new Set(),
acceptedCount = 0,
discardedCount = 0,
scriptletCache = new µb.MRUCache(32), scriptletCache = new µb.MRUCache(32),
exceptionsRegister = new Set(), exceptionsRegister = new Set(),
scriptletsRegister = new Map(), scriptletsRegister = new Map(),
@ -103,6 +105,8 @@
api.reset = function() { api.reset = function() {
scriptletDB.clear(); scriptletDB.clear();
duplicates.clear(); duplicates.clear();
acceptedCount = 0;
discardedCount = 0;
}; };
api.freeze = function() { api.freeze = function() {
@ -154,8 +158,12 @@
reader.select(1001); reader.select(1001);
while ( reader.next() ) { while ( reader.next() ) {
acceptedCount += 1;
var fingerprint = reader.fingerprint(); var fingerprint = reader.fingerprint();
if ( duplicates.has(fingerprint) ) { continue; } if ( duplicates.has(fingerprint) ) {
discardedCount += 1;
continue;
}
duplicates.add(fingerprint); duplicates.add(fingerprint);
var args = reader.args(); var args = reader.args();
if ( args.length < 4 ) { continue; } if ( args.length < 4 ) { continue; }
@ -264,6 +272,19 @@
scriptletDB = new µb.staticExtFilteringEngine.HostnameBasedDB(selfie); scriptletDB = new µb.staticExtFilteringEngine.HostnameBasedDB(selfie);
}; };
Object.defineProperties(api, {
acceptedCount: {
get: function() {
return acceptedCount;
}
},
discardedCount: {
get: function() {
return discardedCount;
}
}
});
return api; return api;
})(); })();

View File

@ -668,6 +668,23 @@
}; };
}; };
Object.defineProperties(api, {
acceptedCount: {
get: function() {
return µb.cosmeticFilteringEngine.acceptedCount +
µb.scriptletFilteringEngine.acceptedCount +
µb.htmlFilteringEngine.acceptedCount;
}
},
discardedCount: {
get: function() {
return µb.cosmeticFilteringEngine.discardedCount +
µb.scriptletFilteringEngine.discardedCount +
µb.htmlFilteringEngine.discardedCount;
}
}
});
api.fromSelfie = function(selfie) { api.fromSelfie = function(selfie) {
µb.cosmeticFilteringEngine.fromSelfie(selfie.cosmetic); µb.cosmeticFilteringEngine.fromSelfie(selfie.cosmetic);
µb.scriptletFilteringEngine.fromSelfie(selfie.scriptlets); µb.scriptletFilteringEngine.fromSelfie(selfie.scriptlets);

View File

@ -562,14 +562,16 @@
var applyCompiledFilters = function(assetKey, compiled) { var applyCompiledFilters = function(assetKey, compiled) {
var snfe = µb.staticNetFilteringEngine, var snfe = µb.staticNetFilteringEngine,
cfe = µb.cosmeticFilteringEngine, sxfe = µb.staticExtFilteringEngine,
acceptedCount = snfe.acceptedCount + cfe.acceptedCount, acceptedCount = snfe.acceptedCount + sxfe.acceptedCount,
discardedCount = snfe.discardedCount + cfe.discardedCount; discardedCount = snfe.discardedCount + sxfe.discardedCount;
µb.applyCompiledFilters(compiled, assetKey === µb.userFiltersPath); µb.applyCompiledFilters(compiled, assetKey === µb.userFiltersPath);
if ( µb.availableFilterLists.hasOwnProperty(assetKey) ) { if ( µb.availableFilterLists.hasOwnProperty(assetKey) ) {
var entry = µb.availableFilterLists[assetKey]; var entry = µb.availableFilterLists[assetKey];
entry.entryCount = snfe.acceptedCount + cfe.acceptedCount - acceptedCount; entry.entryCount = snfe.acceptedCount + sxfe.acceptedCount -
entry.entryUsedCount = entry.entryCount - (snfe.discardedCount + cfe.discardedCount - discardedCount); acceptedCount;
entry.entryUsedCount = entry.entryCount -
(snfe.discardedCount + sxfe.discardedCount - discardedCount);
} }
loadedListKeys.push(assetKey); loadedListKeys.push(assetKey);
}; };