grapher/lib/query/hypernova/hypernova.js

48 lines
1.9 KiB
JavaScript
Raw Normal View History

2016-09-21 18:33:50 +03:00
import applyProps from '../lib/applyProps.js';
import LinkResolve from '../../links/linkTypes/linkResolve.js';
import storeHypernovaResults from './storeHypernovaResults.js';
2016-09-22 12:01:47 +03:00
import assembler from './assembler.js';
2016-09-28 18:30:12 +03:00
import logger from './logger.js';
2016-09-21 18:33:50 +03:00
2016-09-28 18:30:12 +03:00
function hypernova(collectionNode, userId, debug) {
2016-09-21 18:33:50 +03:00
_.each(collectionNode.collectionNodes, childCollectionNode => {
let {filters, options} = applyProps(childCollectionNode);
if (childCollectionNode.linker.isResolver()) {
2016-09-28 18:30:12 +03:00
logger(debug, `[Resolving] ${collectionNode._name} -> ${childCollectionNode.linkName}`, () => {
_.each(collectionNode.results, result => {
const accessor = childCollectionNode.linker.createLink(result);
result[childCollectionNode.linkName] = accessor.find(filters, options);
});
2016-09-21 18:33:50 +03:00
2016-09-28 18:30:12 +03:00
logger.log(debug, `[Resolved] ${childCollectionNode.getName()}: ${collectionNode.results.length} results`)
2016-09-21 18:33:50 +03:00
});
} else {
2016-09-28 18:30:12 +03:00
logger(debug,
`[Fetch and Assembly] ${collectionNode.getName()} -> ${childCollectionNode.linkName}`, () => {
storeHypernovaResults(childCollectionNode, userId, debug);
2016-09-21 18:33:50 +03:00
2016-09-28 18:30:12 +03:00
logger.log(debug, `[Fetch and Assembly] ${childCollectionNode.getName()}: ${childCollectionNode.results.length} results`)
});
hypernova(childCollectionNode, userId, debug);
2016-09-21 18:33:50 +03:00
}
});
}
2016-09-28 18:30:12 +03:00
export default function hypernovaInit(collectionNode, userId, debug) {
2016-09-21 18:33:50 +03:00
let {filters, options} = applyProps(collectionNode);
const collection = collectionNode.collection;
2016-09-28 18:30:12 +03:00
logger(debug, `[Fetch] ${collection._name}`, () => {
collectionNode.results = collection.find(filters, options, userId).fetch();
logger.log(debug, `[Fetch] ${collectionNode.getName()}: ${collectionNode.results.length} results`)
});
hypernova(collectionNode, userId, debug);
2016-09-21 18:33:50 +03:00
2016-09-22 12:01:47 +03:00
return collectionNode.results;
2016-09-21 18:33:50 +03:00
}