Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add matchDebug() for Cliqz #2162

Merged
merged 1 commit into from
Aug 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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