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

Commit 06d0b64b by Mick Hansen

check existing via a map instead of a lodash.find

1 parent 93b0daa1
Showing with 14 additions and 15 deletions
......@@ -350,14 +350,8 @@ module.exports = (function() {
})
delete result.__children
},
primaryKeyAttribute
// Identify singular primaryKey attribute for equality check (if possible)
if (includeOptions.daoFactory.primaryKeyAttributes.length === 1) {
primaryKeyAttribute = includeOptions.daoFactory.primaryKeyAttributes[0]
} else if (includeOptions.daoFactory.rawAttributes.id) {
primaryKeyAttribute = 'id'
}
primaryKeyAttribute = includeOptions.daoFactory.primaryKeyAttribute,
primaryKeyMap = {}
// Ignore all include keys on main data
if (includeOptions.includeNames) {
......@@ -369,18 +363,23 @@ module.exports = (function() {
calleeData = _.omit(row, calleeDataIgnore)
// If there are :M associations included we need to see if the main result of the row has already been identified
existingResult = options.checkExisting && _.find(results, function (result) {
// If we can, detect equality on the singular primary key
if (options.checkExisting) {
if (primaryKeyAttribute) {
return result[primaryKeyAttribute] === calleeData[primaryKeyAttribute]
// If we can, detect equality on the singular primary key
existingResult = primaryKeyMap[calleeData[primaryKeyAttribute]]
} else {
// If we can't identify on a singular primary key, do a full row equality check
existingResult = _.find(results, function (result) {
return Utils._.isEqual(_.omit(result, calleeDataIgnore), calleeData)
})
}
// If we can't identify on a singular primary key, do a full row equality check
return Utils._.isEqual(_.omit(result, calleeDataIgnore), calleeData)
})
}
if (!existingResult) {
results.push(existingResult = calleeData)
if (primaryKeyAttribute) {
primaryKeyMap[existingResult[primaryKeyAttribute]] = existingResult
}
}
for (var attrName in row) {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!