不要怂,就是干,撸起袖子干!

Commit d3dc86ee by Mick Hansen

Merge pull request #1790 from sequelize/perf-groupJoinData

optimize groupJoinData to use a single loop
2 parents 3464ade4 e54f2429
...@@ -363,7 +363,7 @@ module.exports = (function() { ...@@ -363,7 +363,7 @@ module.exports = (function() {
, accessor = Utils._.camelize(key) , accessor = Utils._.camelize(key)
, childOptions , childOptions
, primaryKeyAttribute = include.model.primaryKeyAttribute , primaryKeyAttribute = include.model.primaryKeyAttribute
, isEmpty = value[0] && value[0][primaryKeyAttribute] === null; , isEmpty;
if (!isEmpty) { if (!isEmpty) {
childOptions = { childOptions = {
...@@ -382,9 +382,15 @@ module.exports = (function() { ...@@ -382,9 +382,15 @@ module.exports = (function() {
accessor = accessor.slice(0, 1).toLowerCase() + accessor.slice(1); accessor = accessor.slice(0, 1).toLowerCase() + accessor.slice(1);
if (association.isSingleAssociation) { if (association.isSingleAssociation) {
if (Array.isArray(value)) {
value = value[0];
}
isEmpty = value && value[primaryKeyAttribute] === null;
accessor = Utils.singularize(accessor, self.Model.options.language); accessor = Utils.singularize(accessor, self.Model.options.language);
self[accessor] = self.dataValues[accessor] = isEmpty ? null : include.model.build(value[0], childOptions); self[accessor] = self.dataValues[accessor] = isEmpty ? null : include.model.build(value, childOptions);
} else { } else {
isEmpty = value[0] && value[0][primaryKeyAttribute] === null;
self[accessor] = self.dataValues[accessor] = isEmpty ? [] : include.model.bulkBuild(value, childOptions); self[accessor] = self.dataValues[accessor] = isEmpty ? [] : include.model.bulkBuild(value, childOptions);
} }
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!