From ec939f1c528425c365891489283f9fe704b25866 Mon Sep 17 00:00:00 2001 From: Mike McNeil Date: Wed, 6 Mar 2013 02:39:42 -0600 Subject: [PATCH] Removed transaction from default createEach() --- lib/waterline/adapter.js | 37 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/lib/waterline/adapter.js b/lib/waterline/adapter.js index de280f5b1..960007398 100755 --- a/lib/waterline/adapter.js +++ b/lib/waterline/adapter.js @@ -245,7 +245,7 @@ module.exports = function(adapterDef, cb) { // Warning: Inefficient! App-level tranactions should not be used for built-in compound queries. else { // Create transaction name based on collection - var transactionName = collectionName+'.waterline.default.create.findOrCreate'; + var transactionName = collectionName+'.waterline.default.create'; self.transaction(transactionName, function (err,done) { self.find(collectionName, criteria, function(err, result) { if(err) done(err); @@ -275,7 +275,7 @@ module.exports = function(adapterDef, cb) { // Default behavior else { // Create transaction name based on collection - self.transaction(collectionName+'.waterline.default.createEach', function (err,done) { + self.transaction(collectionName+'.waterline.default.create', function (err,done) { async.forEachSeries(valuesList, function (values,cb) { self.create(collectionName, values, cb); }, done); @@ -301,25 +301,22 @@ module.exports = function(adapterDef, cb) { // Build a list of models var models = []; - // Create transaction name based on collection - self.transaction(collectionName+'.waterline.default.findOrCreateEach', function (err,done) { + async.forEachSeries(valuesList, function (values,cb) { + if (!_.isObject(values)) return cb('findOrCreateEach: Unexpected value in valuesList.'); - async.forEachSeries(valuesList, function (values,cb) { + // Check that each of the criteria keys match: + // build a criteria query + var criteria = {}; + _.each(attributesToCheck, function (attrName) { + criteria[attrName] = values[attrName]; + }); - // Check that each of the criteria keys match: - // build a criteria query - var criteria = {}; - _.each(attributesToCheck, function (attrName) { - criteria[attrName] = values[attrName]; - }); - - return self.findOrCreate(collectionName, criteria, values, function (err, model) { - // Add model to list - if (model) models.push(model); - return cb(err, model); - }); - }, done); - },function (err) { + return self.findOrCreate(collectionName, criteria, values, function (err, model) { + // Add model to list + if (model) models.push(model); + return cb(err, model); + }); + }, function (err) { // Pass back found/created models cb(err,models); }); @@ -414,7 +411,7 @@ module.exports = function(adapterDef, cb) { var acquireLock = function(newLock) { var warningTimer = setTimeout(function() { - console.error("Transaction :: " + newLock.name + " is taking an abnormally long time (> " + self.config.transactionWarningTimer + "ms)"); + console.error("Transaction :: " + newLock.name + " is taking an abnormally long time (> " + waterlineConfig.transactionWarningTimer + "ms)"); }, waterlineConfig.transactionWarningTimer); newLock.atomicLogic(null, function unlock () {