Skip to content

Commit 5c20182

Browse files
committed
fix regression in per-list filter counts (reported by @mapx-)
1 parent 707d770 commit 5c20182

4 files changed

Lines changed: 68 additions & 7 deletions

File tree

src/js/html-filtering.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
filterDB = new µb.staticExtFilteringEngine.HostnameBasedDB(),
3131
pselectors = new Map(),
3232
duplicates = new Set(),
33+
acceptedCount = 0,
34+
discardedCount = 0,
3335
docRegister, loggerRegister;
3436

3537
var PSelectorHasTask = function(task) {
@@ -224,6 +226,8 @@
224226
filterDB.clear();
225227
pselectors.clear();
226228
duplicates.clear();
229+
acceptedCount = 0;
230+
discardedCount = 0;
227231
};
228232

229233
api.freeze = function() {
@@ -260,8 +264,12 @@
260264
reader.select(1002);
261265

262266
while ( reader.next() ) {
267+
acceptedCount += 1;
263268
var fingerprint = reader.fingerprint();
264-
if ( duplicates.has(fingerprint) ) { continue; }
269+
if ( duplicates.has(fingerprint) ) {
270+
discardedCount += 1;
271+
continue;
272+
}
265273
duplicates.add(fingerprint);
266274
var args = reader.args();
267275
filterDB.add(args[1], {
@@ -374,6 +382,19 @@
374382
}
375383
};
376384

385+
Object.defineProperties(api, {
386+
acceptedCount: {
387+
get: function() {
388+
return acceptedCount;
389+
}
390+
},
391+
discardedCount: {
392+
get: function() {
393+
return discardedCount;
394+
}
395+
}
396+
});
397+
377398
return api;
378399
})();
379400

src/js/scriptlet-filtering.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
var µb = µBlock,
3030
scriptletDB = new µb.staticExtFilteringEngine.HostnameBasedDB(),
3131
duplicates = new Set(),
32+
acceptedCount = 0,
33+
discardedCount = 0,
3234
scriptletCache = new µb.MRUCache(32),
3335
exceptionsRegister = new Set(),
3436
scriptletsRegister = new Map(),
@@ -103,6 +105,8 @@
103105
api.reset = function() {
104106
scriptletDB.clear();
105107
duplicates.clear();
108+
acceptedCount = 0;
109+
discardedCount = 0;
106110
};
107111

108112
api.freeze = function() {
@@ -154,8 +158,12 @@
154158
reader.select(1001);
155159

156160
while ( reader.next() ) {
161+
acceptedCount += 1;
157162
var fingerprint = reader.fingerprint();
158-
if ( duplicates.has(fingerprint) ) { continue; }
163+
if ( duplicates.has(fingerprint) ) {
164+
discardedCount += 1;
165+
continue;
166+
}
159167
duplicates.add(fingerprint);
160168
var args = reader.args();
161169
if ( args.length < 4 ) { continue; }
@@ -264,6 +272,19 @@
264272
scriptletDB = new µb.staticExtFilteringEngine.HostnameBasedDB(selfie);
265273
};
266274

275+
Object.defineProperties(api, {
276+
acceptedCount: {
277+
get: function() {
278+
return acceptedCount;
279+
}
280+
},
281+
discardedCount: {
282+
get: function() {
283+
return discardedCount;
284+
}
285+
}
286+
});
287+
267288
return api;
268289
})();
269290

src/js/static-ext-filtering.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -668,6 +668,23 @@
668668
};
669669
};
670670

671+
Object.defineProperties(api, {
672+
acceptedCount: {
673+
get: function() {
674+
return µb.cosmeticFilteringEngine.acceptedCount +
675+
µb.scriptletFilteringEngine.acceptedCount +
676+
µb.htmlFilteringEngine.acceptedCount;
677+
}
678+
},
679+
discardedCount: {
680+
get: function() {
681+
return µb.cosmeticFilteringEngine.discardedCount +
682+
µb.scriptletFilteringEngine.discardedCount +
683+
µb.htmlFilteringEngine.discardedCount;
684+
}
685+
}
686+
});
687+
671688
api.fromSelfie = function(selfie) {
672689
µb.cosmeticFilteringEngine.fromSelfie(selfie.cosmetic);
673690
µb.scriptletFilteringEngine.fromSelfie(selfie.scriptlets);

src/js/storage.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -562,14 +562,16 @@
562562

563563
var applyCompiledFilters = function(assetKey, compiled) {
564564
var snfe = µb.staticNetFilteringEngine,
565-
cfe = µb.cosmeticFilteringEngine,
566-
acceptedCount = snfe.acceptedCount + cfe.acceptedCount,
567-
discardedCount = snfe.discardedCount + cfe.discardedCount;
565+
sxfe = µb.staticExtFilteringEngine,
566+
acceptedCount = snfe.acceptedCount + sxfe.acceptedCount,
567+
discardedCount = snfe.discardedCount + sxfe.discardedCount;
568568
µb.applyCompiledFilters(compiled, assetKey === µb.userFiltersPath);
569569
if ( µb.availableFilterLists.hasOwnProperty(assetKey) ) {
570570
var entry = µb.availableFilterLists[assetKey];
571-
entry.entryCount = snfe.acceptedCount + cfe.acceptedCount - acceptedCount;
572-
entry.entryUsedCount = entry.entryCount - (snfe.discardedCount + cfe.discardedCount - discardedCount);
571+
entry.entryCount = snfe.acceptedCount + sxfe.acceptedCount -
572+
acceptedCount;
573+
entry.entryUsedCount = entry.entryCount -
574+
(snfe.discardedCount + sxfe.discardedCount - discardedCount);
573575
}
574576
loadedListKeys.push(assetKey);
575577
};

0 commit comments

Comments
 (0)