Merge pull request #1007 from horiaradu/master
Optimize related model queries
This commit is contained in:
commit
c2a683bca4
|
@ -212,6 +212,9 @@ Inclusion.include = function(objects, include, options, cb) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!foreignKeys.length) {
|
||||||
|
return cb(null, []);
|
||||||
|
}
|
||||||
if (filter.limit || filter.skip || filter.offset) {
|
if (filter.limit || filter.skip || filter.offset) {
|
||||||
// Force the find to be performed per FK to honor the pagination
|
// Force the find to be performed per FK to honor the pagination
|
||||||
pageSize = 1;
|
pageSize = 1;
|
||||||
|
@ -235,6 +238,10 @@ Inclusion.include = function(objects, include, options, cb) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var items = [];
|
var items = [];
|
||||||
|
// Optimization: no need to resolve keys that are an empty array
|
||||||
|
listOfFKs = listOfFKs.filter(function(keys) {
|
||||||
|
return keys.length > 0;
|
||||||
|
});
|
||||||
async.each(listOfFKs, function(foreignKeys, done) {
|
async.each(listOfFKs, function(foreignKeys, done) {
|
||||||
var newFilter = {};
|
var newFilter = {};
|
||||||
for (var f in filter) {
|
for (var f in filter) {
|
||||||
|
|
Loading…
Reference in New Issue