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

Commit cfdd4f3f by Mick Hansen

add new bulkBuild method, provides performance benefits by not building option o…

…bjects multiple times, in time perhaps more benefits
1 parent 861fd2d8
......@@ -666,6 +666,9 @@ module.exports = (function() {
}
DAOFactory.prototype.build = function(values, options) {
if (Array.isArray(values)) {
return this.bulkBuild(values, options)
}
options = options || { isNewRecord: true, isDirty: true }
if (options.hasOwnProperty('include') && options.include && !options.includeValidated) {
......@@ -675,6 +678,12 @@ module.exports = (function() {
return new this.DAO(values, options)
}
DAOFactory.prototype.bulkBuild = function(valueSets, options) {
return valueSets.map(function (values) {
return this.build(values, options)
}.bind(this))
}
DAOFactory.prototype.create = function(values, fieldsOrOptions) {
Utils.validateParameter(values, Object, { optional: true })
Utils.validateParameter(fieldsOrOptions, Object, { deprecated: Array, optional: true, index: 2, method: 'DAOFactory#create' })
......
......@@ -224,12 +224,7 @@ module.exports = (function() {
, self = this
var accessor = Utils._.camelize(key)
// downcase the first char
accessor = accessor.slice(0,1).toLowerCase() + accessor.slice(1)
value.forEach(function(data) {
var daoInstance = include.daoFactory.build(data, {
var childOptions = {
isNewRecord: false,
isDirty: false,
include: include.include,
......@@ -237,7 +232,13 @@ module.exports = (function() {
includeMap: include.includeMap,
includeValidated: true,
raw: options.raw
})
}
// downcase the first char
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) {
......
......@@ -238,8 +238,7 @@ module.exports = (function() {
checkExisting: this.options.hasMultiAssociation
})
result = results.map(function(result) {
return this.callee.build(result, {
result = this.callee.bulkBuild(results, {
isNewRecord: false,
isDirty: false,
include:this.options.include,
......@@ -248,7 +247,6 @@ module.exports = (function() {
includeValidated: true,
raw: true
})
}.bind(this))
} else if (this.options.hasJoinTableModel === true) {
result = results.map(function(result) {
result = Dot.transform(result)
......@@ -267,9 +265,11 @@ module.exports = (function() {
// Regular queries
} else {
result = results.map(function(result) {
return this.callee.build(result, { isNewRecord: false, isDirty: false, raw: true })
}.bind(this))
result = this.callee.bulkBuild(results, {
isNewRecord: false,
isDirty: false,
raw: true
})
}
// return the first real model instance if options.plain is set (e.g. Model.find)
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!