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

Commit 06d0b64b by Mick Hansen

check existing via a map instead of a lodash.find

1 parent 93b0daa1
Showing with 12 additions and 13 deletions
...@@ -350,14 +350,8 @@ module.exports = (function() { ...@@ -350,14 +350,8 @@ module.exports = (function() {
}) })
delete result.__children delete result.__children
}, },
primaryKeyAttribute primaryKeyAttribute = includeOptions.daoFactory.primaryKeyAttribute,
primaryKeyMap = {}
// 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'
}
// Ignore all include keys on main data // Ignore all include keys on main data
if (includeOptions.includeNames) { if (includeOptions.includeNames) {
...@@ -369,18 +363,23 @@ module.exports = (function() { ...@@ -369,18 +363,23 @@ module.exports = (function() {
calleeData = _.omit(row, calleeDataIgnore) 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 // 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 (options.checkExisting) {
// If we can, detect equality on the singular primary key
if (primaryKeyAttribute) { 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 // 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) return Utils._.isEqual(_.omit(result, calleeDataIgnore), calleeData)
}) })
}
}
if (!existingResult) { if (!existingResult) {
results.push(existingResult = calleeData) results.push(existingResult = calleeData)
if (primaryKeyAttribute) {
primaryKeyMap[existingResult[primaryKeyAttribute]] = existingResult
}
} }
for (var attrName in row) { 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!