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

Commit 6c9a76dc by Mick Hansen

Optimize child include build performance

1 parent c0c3fadb
Showing with 12 additions and 18 deletions
Notice: All 1.7.x changes are present in 2.0.x aswell Notice: All 1.7.x changes are present in 2.0.x aswell
# v2.0.0-dev10 # v2.0.0-dev10
- [PERFORMANCE] increased build performance when using include, which speeds up findAll etc.
#### Backwards compatability changes #### Backwards compatability changes
- selectedValues has been removed for performance reasons, if you depend on this, please open an issue and we will help you work around it. - selectedValues has been removed for performance reasons, if you depend on this, please open an issue and we will help you work around it.
- foreign keys will now correctly be based on the alias of the model - foreign keys will now correctly be based on the alias of the model
......
...@@ -220,9 +220,13 @@ module.exports = (function() { ...@@ -220,9 +220,13 @@ module.exports = (function() {
}) })
var association = include.association var association = include.association
, self = this , self = this
, accessor = Utils._.camelize(key)
, childOptions
, primaryKeyAttribute = include.daoFactory.primaryKeyAttribute
, isEmpty = value[0] && value[0][primaryKeyAttribute] === null
var accessor = Utils._.camelize(key) if (!isEmpty) {
var childOptions = { childOptions = {
isNewRecord: false, isNewRecord: false,
isDirty: false, isDirty: false,
include: include.include, include: include.include,
...@@ -231,29 +235,17 @@ module.exports = (function() { ...@@ -231,29 +235,17 @@ module.exports = (function() {
includeValidated: true, includeValidated: true,
raw: options.raw raw: options.raw
} }
}
// downcase the first char // downcase the first char
accessor = accessor.slice(0,1).toLowerCase() + accessor.slice(1) accessor = accessor.slice(0,1).toLowerCase() + accessor.slice(1)
value.forEach(function(data) {
var daoInstance = include.daoFactory.build(data, childOptions)
, isEmpty = !Utils.firstValueOfHash(daoInstance.identifiers)
if (association.isSingleAssociation) { if (association.isSingleAssociation) {
accessor = Utils.singularize(accessor, self.sequelize.language) accessor = Utils.singularize(accessor, self.Model.options.language)
self.dataValues[accessor] = isEmpty ? null : daoInstance self[accessor] = self.dataValues[accessor] = isEmpty ? null : include.daoFactory.build(value[0], childOptions)
self[accessor] = self.dataValues[accessor]
} else { } else {
if (!self.dataValues[accessor]) { self[accessor] = self.dataValues[accessor] = isEmpty ? [] : include.daoFactory.bulkBuild(value, childOptions)
self.dataValues[accessor] = []
self[accessor] = self.dataValues[accessor]
}
if (!isEmpty) {
self.dataValues[accessor].push(daoInstance)
} }
}
}.bind(this))
}; };
// if an array with field names is passed to save() // if an array with field names is passed to save()
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!