Skip to content

Commit

Permalink
Removed transaction from default createEach()
Browse files Browse the repository at this point in the history
  • Loading branch information
mikermcneil committed Mar 6, 2013
1 parent 96dcaf0 commit ec939f1
Showing 1 changed file with 17 additions and 20 deletions.
37 changes: 17 additions & 20 deletions lib/waterline/adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
});
Expand Down Expand Up @@ -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 () {
Expand Down

0 comments on commit ec939f1

Please sign in to comment.