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

Commit d3dc86ee by Mick Hansen

Merge pull request #1790 from sequelize/perf-groupJoinData

optimize groupJoinData to use a single loop
2 parents 3464ade4 e54f2429
......@@ -362,8 +362,8 @@ module.exports = (function() {
, self = this
, accessor = Utils._.camelize(key)
, childOptions
, primaryKeyAttribute = include.model.primaryKeyAttribute
, isEmpty = value[0] && value[0][primaryKeyAttribute] === null;
, primaryKeyAttribute = include.model.primaryKeyAttribute
, isEmpty;
if (!isEmpty) {
childOptions = {
......@@ -382,9 +382,15 @@ module.exports = (function() {
accessor = accessor.slice(0, 1).toLowerCase() + accessor.slice(1);
if (association.isSingleAssociation) {
if (Array.isArray(value)) {
value = value[0];
}
isEmpty = value && value[primaryKeyAttribute] === null;
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 {
isEmpty = value[0] && value[0][primaryKeyAttribute] === null;
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!