mirror of https://github.com/gorhill/uBlock.git
Make loadBenchmarkDataset() compatible with more recent requests.json
The format of requests.json used in latest Cliqz benchmark code has changed from the original one -- this commit makes the dataset load code also compatible with the new format. More recent dataset used in Cliqz benchmark code: - https://github.com/mjethani/scaling-palm-tree Cliqz benchmark code: - https://github.com/ghostery/adblocker/tree/master/packages/adblocker-benchmarks
This commit is contained in:
parent
7da0ccd55b
commit
7ca2c8a9a7
|
@ -94,14 +94,30 @@ const loadBenchmarkDataset = (( ) => {
|
||||||
console.info(`Loading benchmark dataset...`);
|
console.info(`Loading benchmark dataset...`);
|
||||||
datasetPromise = io.fetchText(datasetURL).then(details => {
|
datasetPromise = io.fetchText(datasetURL).then(details => {
|
||||||
console.info(`Parsing benchmark dataset...`);
|
console.info(`Parsing benchmark dataset...`);
|
||||||
const requests = [];
|
let requests = [];
|
||||||
const lineIter = new LineIterator(details.content);
|
if ( details.content.startsWith('[') ) {
|
||||||
while ( lineIter.eot() === false ) {
|
|
||||||
let request;
|
|
||||||
try {
|
try {
|
||||||
request = JSON.parse(lineIter.next());
|
requests = JSON.parse(details.content);
|
||||||
} catch(ex) {
|
} catch(ex) {
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
const lineIter = new LineIterator(details.content);
|
||||||
|
const parsed = [];
|
||||||
|
while ( lineIter.eot() === false ) {
|
||||||
|
const line = lineIter.next().trim();
|
||||||
|
if ( line === '' ) { continue; }
|
||||||
|
try {
|
||||||
|
parsed.push(JSON.parse(line));
|
||||||
|
} catch(ex) {
|
||||||
|
parsed.length = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
requests = parsed;
|
||||||
|
}
|
||||||
|
if ( requests.length === 0 ) { return; }
|
||||||
|
const out = [];
|
||||||
|
for ( const request of requests ) {
|
||||||
if ( request instanceof Object === false ) { continue; }
|
if ( request instanceof Object === false ) { continue; }
|
||||||
if ( !request.frameUrl || !request.url ) { continue; }
|
if ( !request.frameUrl || !request.url ) { continue; }
|
||||||
if ( request.cpt === 'document' ) {
|
if ( request.cpt === 'document' ) {
|
||||||
|
@ -109,9 +125,9 @@ const loadBenchmarkDataset = (( ) => {
|
||||||
} else if ( request.cpt === 'xhr' ) {
|
} else if ( request.cpt === 'xhr' ) {
|
||||||
request.cpt = 'xmlhttprequest';
|
request.cpt = 'xmlhttprequest';
|
||||||
}
|
}
|
||||||
requests.push(request);
|
out.push(request);
|
||||||
}
|
}
|
||||||
return requests;
|
return out;
|
||||||
}).catch(details => {
|
}).catch(details => {
|
||||||
console.info(`Not found: ${details.url}`);
|
console.info(`Not found: ${details.url}`);
|
||||||
datasetPromise = undefined;
|
datasetPromise = undefined;
|
||||||
|
|
Loading…
Reference in New Issue