MCPcopy
hub / github.com/Automattic/mongoose / splitPopulateQuery

Function splitPopulateQuery

lib/helpers/populate/splitPopulateQuery.js:43–72  ·  view source on GitHub ↗
(mod, ids, select, assignmentOpts)

Source from the content-addressed store, hash-verified

41 */
42
43function splitPopulateQuery(mod, ids, select, assignmentOpts) {
44 if (mod.docs.length <= 1) {
45 return null;
46 }
47 const perDocumentLimit = mod.options.perDocumentLimit == null ?
48 get(mod.options, 'options.perDocumentLimit', null) :
49 mod.options.perDocumentLimit;
50 const numInFilterElements = ids.length * mod.foreignField.size;
51 if (perDocumentLimit == null && (numInFilterElements <= splitPopulateQuery.maxInFilterLength || mod.isRefPath)) {
52 return null;
53 }
54
55 return mod.docs.map((doc, i) => {
56 const subMod = {
57 ...mod,
58 docs: [doc],
59 ids: [mod.ids[i]],
60 allIds: [mod.allIds[i]],
61 unpopulatedValues: [mod.unpopulatedValues[i]],
62 match: Array.isArray(mod.match) ? [mod.match[i]] : mod.match,
63 _assignFromOwnResults: !mod.isRefPath
64 };
65 let subIds = utils.array.flatten(subMod.ids, flatten);
66 subIds = utils.array.unique(subIds);
67 const match = subIds.length === 0 || subIds.every(utils.isNullOrUndefined) ?
68 null :
69 createPopulateQueryFilter(subIds, subMod.match, subMod.foreignField, subMod.model, subMod.options.skipInvalidIds);
70 return [subMod, match, select, assignmentOpts];
71 });
72}
73
74/*!
75 * ignore

Callers 2

_populatePathFunction · 0.85

Calls 1

getFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…