Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6ae5c25
commit f187d26
Showing
5 changed files
with
187 additions
and
4 deletions.
There are no files selected for viewing
65 changes: 65 additions & 0 deletions
65
benchmark/doxbee-sequential-errors/promises-then-promise.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
global.useThenPromise = true; | ||
|
||
var promise = require("promise"); | ||
|
||
require('../lib/fakesP'); | ||
|
||
|
||
module.exports = function upload(stream, idOrPath, tag, done) { | ||
var blob = blobManager.create(account); | ||
var tx = db.begin(); | ||
var blobIdP = blob.put(stream); | ||
var fileP = self.byUuidOrPath(idOrPath).get(); | ||
var version, fileId, file; | ||
promise.all([blobIdP, fileP]).then(function(all) { | ||
var blobId = all[0], fileV = all[1]; | ||
file = fileV; | ||
var previousId = file ? file.version : null; | ||
version = { | ||
userAccountId: userAccount.id, | ||
date: new Date(), | ||
blobId: blobId, | ||
creatorId: userAccount.id, | ||
previousId: previousId, | ||
}; | ||
version.id = Version.createHash(version); | ||
return Version.insert(version).execWithin(tx); | ||
}).then(function() { | ||
triggerIntentionalError(); | ||
if (!file) { | ||
var splitPath = idOrPath.split('/'); | ||
var fileName = splitPath[splitPath.length - 1]; | ||
var newId = uuid.v1(); | ||
return self.createQueryCtxless(idOrPath, { | ||
id: newId, | ||
userAccountId: userAccount.id, | ||
name: fileName, | ||
version: version.id | ||
}).then(function(q) { | ||
return q.execWithin(tx); | ||
}).then(function() { | ||
return newId; | ||
}); | ||
} else { | ||
return file.id; | ||
} | ||
}).then(function(fileIdV) { | ||
triggerIntentionalError(); | ||
fileId = fileIdV; | ||
return FileVersion.insert({ | ||
fileId: fileId, | ||
versionId: version.id | ||
}).execWithin(tx); | ||
}).then(function() { | ||
triggerIntentionalError(); | ||
return File.whereUpdate({id: fileId}, {version: version.id}) | ||
.execWithin(tx); | ||
}).then(function() { | ||
triggerIntentionalError(); | ||
tx.commit(); | ||
return done(); | ||
}).then(null, function(err) { | ||
tx.rollback(); | ||
return done(err); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
global.useThenPromise = true; | ||
|
||
var promise = require("promise"); | ||
|
||
require('../lib/fakesP'); | ||
|
||
|
||
module.exports = function upload(stream, idOrPath, tag, done) { | ||
var blob = blobManager.create(account); | ||
var tx = db.begin(); | ||
var blobIdP = blob.put(stream); | ||
var fileP = self.byUuidOrPath(idOrPath).get(); | ||
var version, fileId, file; | ||
promise.all([blobIdP, fileP]).then(function(all) { | ||
var blobId = all[0], fileV = all[1]; | ||
file = fileV; | ||
var previousId = file ? file.version : null; | ||
version = { | ||
userAccountId: userAccount.id, | ||
date: new Date(), | ||
blobId: blobId, | ||
creatorId: userAccount.id, | ||
previousId: previousId, | ||
}; | ||
version.id = Version.createHash(version); | ||
return Version.insert(version).execWithin(tx); | ||
}).then(function() { | ||
if (!file) { | ||
var splitPath = idOrPath.split('/'); | ||
var fileName = splitPath[splitPath.length - 1]; | ||
var newId = uuid.v1(); | ||
return self.createQueryCtxless(idOrPath, { | ||
id: newId, | ||
userAccountId: userAccount.id, | ||
name: fileName, | ||
version: version.id | ||
}).then(function(q) { | ||
return q.execWithin(tx); | ||
}).then(function() { | ||
return newId; | ||
}); | ||
} else { | ||
return file.id; | ||
} | ||
}).then(function(fileIdV) { | ||
fileId = fileIdV; | ||
return FileVersion.insert({ | ||
fileId: fileId, | ||
versionId: version.id | ||
}).execWithin(tx); | ||
}).then(function() { | ||
return File.whereUpdate({id: fileId}, {version: version.id}) | ||
.execWithin(tx); | ||
}).then(function() { | ||
tx.commit(); | ||
return done(); | ||
}, function(err) { | ||
tx.rollback(); | ||
return done(err); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
global.useThenPromise = true; | ||
|
||
var Promise = require("promise"); | ||
|
||
require('../lib/fakesP'); | ||
|
||
module.exports = function upload(stream, idOrPath, tag, done) { | ||
var queries = new Array(global.parallelQueries); | ||
var tx = db.begin(); | ||
|
||
for( var i = 0, len = queries.length; i < len; ++i ) { | ||
queries[i] = FileVersion.insert({index: i}).execWithin(tx); | ||
} | ||
|
||
Promise.all(queries).then().then(function() { | ||
tx.commit(); | ||
done(); | ||
}, function(err) { | ||
tx.rollback(); | ||
done(err); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters