Skip to content

Commit

Permalink
Add matchDebug() for Cliqz
Browse files Browse the repository at this point in the history
  • Loading branch information
mjethani committed Aug 12, 2021
1 parent 15ce757 commit 0737917
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
12 changes: 11 additions & 1 deletion packages/adblocker-benchmarks/blockers/cliqz-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@
const { FiltersEngine, Request } = require('@cliqz/adblocker/dist/adblocker.umd.min.js');

module.exports = class Cliqz {
static parse(rawLists, enableCompression) {
static parse(rawLists, { enableCompression = false, debug = false } = {}) {
return new Cliqz(FiltersEngine.parse(rawLists, {
enableCompression,
integrityCheck: false,
loadCosmeticFilters: false,
debug,
}));
}

Expand All @@ -36,4 +37,13 @@ module.exports = class Cliqz {
type,
})).match;
}

matchDebug({ url, frameUrl, type }) {
const { filter = null } = this.engine.match(Request.fromRawDetails({
url,
sourceUrl: frameUrl,
type,
}));
return filter !== null ? filter.rawLine : null;
}
};
4 changes: 2 additions & 2 deletions packages/adblocker-benchmarks/blockers/cliqz-compression.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
const CliqzBase = require('./cliqz-base');

module.exports = class CliqzCompression extends CliqzBase {
static parse(rawLists) {
return super.parse(rawLists, true);
static parse(rawLists, { debug = false } = {}) {
return super.parse(rawLists, { enableCompression: true, debug });
}
};
4 changes: 2 additions & 2 deletions packages/adblocker-benchmarks/blockers/cliqz.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
const CliqzBase = require('./cliqz-base');

module.exports = class Cliqz extends CliqzBase {
static parse(rawLists) {
return super.parse(rawLists, false);
static parse(rawLists, { debug = false } = {}) {
return super.parse(rawLists, { debug });
}
};
2 changes: 1 addition & 1 deletion packages/adblocker-benchmarks/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ async function debug(moduleId, rawLists) {
await Cls.initialize({ hostsOnly: HOSTS_ONLY });
}

const engine = await Cls.parse(rawLists);
const engine = await Cls.parse(rawLists, { debug: true });

for (let index = 0; index < requests.length; index += 1) {
const { url, frameUrl, cpt } = requests[index];
Expand Down

0 comments on commit 0737917

Please sign in to comment.