mirror of
https://github.com/vale981/grapher
synced 2025-03-05 09:31:42 -05:00
Performance fixes for assembler
This commit is contained in:
parent
eef3f4df0d
commit
3d26c74b62
1 changed files with 44 additions and 12 deletions
|
@ -20,13 +20,51 @@ export default (childCollectionNode, {limit, skip, metaFilters}) => {
|
|||
})
|
||||
}
|
||||
|
||||
_.each(parent.results, result => {
|
||||
let data = assembleData(childCollectionNode, result, {
|
||||
fieldStorage, strategy, isSingle
|
||||
});
|
||||
const resultsByKeyId = _.groupBy(childCollectionNode.results, '_id');
|
||||
|
||||
result[childCollectionNode.linkName] = filterAssembledData(data, {limit, skip})
|
||||
});
|
||||
if (strategy === 'one') {
|
||||
parent.results.forEach(parentResult => {
|
||||
parentResult[childCollectionNode.linkName] =
|
||||
filterAssembledData(
|
||||
resultsByKeyId[parentResult[fieldStorage]],
|
||||
{limit, skip}
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
if (strategy === 'many') {
|
||||
parent.results.forEach(parentResult => {
|
||||
let data = [];
|
||||
parentResult[fieldStorage].forEach(_id => {
|
||||
data.push(resultsByKeyId[_id]);
|
||||
})
|
||||
|
||||
parentResult[childCollectionNode.linkName] = filterAssembledData(data, {limit, skip});
|
||||
})
|
||||
}
|
||||
|
||||
if (strategy === 'one-meta') {
|
||||
parent.results.forEach(parentResult => {
|
||||
parentResult[childCollectionNode.linkName] =
|
||||
filterAssembledData(
|
||||
resultsByKeyId[parentResult[fieldStorage]._id],
|
||||
{limit, skip}
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
if (strategy === 'many-meta') {
|
||||
parent.results.forEach(parentResult => {
|
||||
const _ids = _.pluck(parentResult[fieldStorage], '_id');
|
||||
let data = [];
|
||||
_ids.forEach(_id => {
|
||||
data.push(resultsByKeyId[_id]);
|
||||
})
|
||||
|
||||
parentResult[childCollectionNode.linkName] = filterAssembledData(data, {limit, skip});
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
function filterAssembledData(data, {limit, skip}) {
|
||||
|
@ -36,9 +74,3 @@ function filterAssembledData(data, {limit, skip}) {
|
|||
|
||||
return data;
|
||||
}
|
||||
|
||||
function assembleData(childCollectionNode, result, {fieldStorage, strategy}) {
|
||||
const filters = createSearchFilters(result, fieldStorage, strategy, false);
|
||||
|
||||
return sift(filters, childCollectionNode.results);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue