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

Commit 6c9a76dc by Mick Hansen

Optimize child include build performance

1 parent c0c3fadb
Showing with 23 additions and 29 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,40 +220,32 @@ module.exports = (function() { ...@@ -220,40 +220,32 @@ module.exports = (function() {
}) })
var association = include.association var association = include.association
, self = this , self = this
, accessor = Utils._.camelize(key)
var accessor = Utils._.camelize(key) , childOptions
var childOptions = { , primaryKeyAttribute = include.daoFactory.primaryKeyAttribute
isNewRecord: false, , isEmpty = value[0] && value[0][primaryKeyAttribute] === null
isDirty: false,
include: include.include, if (!isEmpty) {
includeNames: include.includeNames, childOptions = {
includeMap: include.includeMap, isNewRecord: false,
includeValidated: true, isDirty: false,
raw: options.raw include: include.include,
includeNames: include.includeNames,
includeMap: include.includeMap,
includeValidated: true,
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) { if (association.isSingleAssociation) {
var daoInstance = include.daoFactory.build(data, childOptions) accessor = Utils.singularize(accessor, self.Model.options.language)
, isEmpty = !Utils.firstValueOfHash(daoInstance.identifiers) self[accessor] = self.dataValues[accessor] = isEmpty ? null : include.daoFactory.build(value[0], childOptions)
} else {
if (association.isSingleAssociation) { self[accessor] = self.dataValues[accessor] = isEmpty ? [] : include.daoFactory.bulkBuild(value, childOptions)
accessor = Utils.singularize(accessor, self.sequelize.language) }
self.dataValues[accessor] = isEmpty ? null : daoInstance
self[accessor] = self.dataValues[accessor]
} else {
if (!self.dataValues[accessor]) {
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!