src/cache/server/cache-server.js
function collectionLookup (collection, query) {
	const id = createID(query.pattern, query.language);
	log(`collectionLookup: querying for ${id}`);
	return collection.find({_id: id}, {result: 1}).toArray()
		.then(
			(docs) => {
				log(`collectionLookup: Got ${docs.length} docs`);
				if (docs.length === 0) {
					log(`collectionLookup ${createID(query.pattern, query.language)}: no results`);
					return Promise.resolve(PATTERN_UNKNOWN);
				} else if (docs.length === 1) {
					log(`collectionLookup ${query.pattern}-${query.language}: result: ${docs[0].result}`);
					return Promise.resolve(docs[0]);
				} else {
					log(`collectionLookup unexpected multiple match: ${jsonStringify(docs)}`);
					return Promise.resolve(PATTERN_UNKNOWN);
				}
			},
			(e) => {
				log(`collectionLookup error: ${e}`);
				return Promise.resolve(PATTERN_UNKNOWN);
			}
		);
}
function collectionLookup (collection, query) {
	const id = createID(query.pattern, query.language);
	log(`collectionLookup: querying for ${id}`);
	return collection.find({_id: id}, {result: 1}).toArray()
		.then(
			(docs) => {
				log(`collectionLookup: Got ${docs.length} docs`);
				if (docs.length === 0) {
					log(`collectionLookup ${createID(query.pattern, query.language)}: no results`);
					return Promise.resolve(PATTERN_UNKNOWN);
				} else if (docs.length === 1) {
					log(`collectionLookup ${query.pattern}-${query.language}: result: ${docs[0].result}`);
					return Promise.resolve(docs[0]);
				} else {
					log(`collectionLookup unexpected multiple match: ${jsonStringify(docs)}`);
					return Promise.resolve(PATTERN_UNKNOWN);
				}
			},
			(e) => {
				log(`collectionLookup error: ${e}`);
				return Promise.resolve(PATTERN_UNKNOWN);
			}
		);
}
function collectionLookup ( collection , query ) { const id = createID ( query . pattern , query . language ) ; log ( ` ${ id } ` ) ; return collection . find ( { _id : id } , { result : 1 } ) . toArray ( ) . then ( ( docs ) => { log ( ` ${ docs . length } ` ) ; if ( docs . length === 0 ) { log ( ` ${ createID ( query . pattern , query . language ) } ` ) ; return Promise . resolve ( PATTERN_UNKNOWN ) ; } else if ( docs . length === 1 ) { log ( ` ${ query . pattern } ${ query . language } ${ docs [ 0 ] . result } ` ) ; return Promise . resolve ( docs [ 0 ] ) ; } else { log ( ` ${ jsonStringify ( docs ) } ` ) ; return Promise . resolve ( PATTERN_UNKNOWN ) ; } } , ( e ) => { log ( ` ${ e } ` ) ; return Promise . resolve ( PATTERN_UNKNOWN ) ; } ) ; }
Helper for isVulnerable. Returns a Promise that resolves to one of the PATTERN_X results.
Helper for isVulnerable . Returns a Promise that resolves to one of the PATTERN_X results .