Skip to content

Commit

Permalink
Fixes #1400
Browse files Browse the repository at this point in the history
  • Loading branch information
petkaantonov committed Oct 4, 2017
1 parent cae7cb7 commit a6abe60
Show file tree
Hide file tree
Showing 6 changed files with 2,948 additions and 45 deletions.
2 changes: 2 additions & 0 deletions bench
Expand Up @@ -5,6 +5,8 @@ nodepath=${2:-node}
shift 2;
cwd=${PWD}

export NODE_ENV=production

trap 'cd "$cwd"' EXIT

if [ "$benchmark" = "doxbee" ]; then
Expand Down
2 changes: 1 addition & 1 deletion benchmark/analysis/promises-bluebird.js
Expand Up @@ -10,7 +10,7 @@ module.exports = function upload(stream, idOrPath, tag, done) {
var fileP = self.byUuidOrPath(idOrPath).get();
var version, fileId, file;

bluebird.all([blobIdP, fileP]).spread(function(blobId, fileV) {
bluebird.join(blobIdP, fileP, function(blobId, fileV) {
file = fileV;
var previousId = file ? file.version : null;
version = {
Expand Down
51 changes: 51 additions & 0 deletions benchmark/doxbee-sequential/promises-native-async-await.js
@@ -0,0 +1,51 @@
global.useNative = true;

try {
if (Promise.race.toString() !== 'function race() { [native code] }')
throw 0;
} catch (e) {
throw new Error("No ES6 promises available");
}

require('../lib/fakesP');

module.exports = async function upload(stream, idOrPath, tag, done) {
try {
var blob = blobManager.create(account);
var tx = db.begin();
var blobId = await blob.put(stream);
var file = await self.byUuidOrPath(idOrPath).get();

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);
await Version.insert(version).execWithin(tx);
if (!file) {
var splitPath = idOrPath.split('/');
var fileName = splitPath[splitPath.length - 1];
file = {
id: uuid.v1(),
userAccountId: userAccount.id,
name: fileName,
version: version.id
}
var query = await self.createQuery(idOrPath, file);
await query.execWithin(tx);
}
await FileVersion.insert({fileId: file.id, versionId: version.id})
.execWithin(tx);
await File.whereUpdate({id: file.id}, {version: version.id})
.execWithin(tx);
tx.commit();
done();
} catch (err) {
tx.rollback();
done(err);
}
};
29 changes: 29 additions & 0 deletions benchmark/madeup-parallel/promises-native-async-await.js
@@ -0,0 +1,29 @@
global.useNative = true;

try {
if (Promise.race.toString() !== 'function race() { [native code] }')
throw 0;
} catch (e) {
throw new Error("No ES6 promises available");
}

require('../lib/fakesP');

module.exports = async 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);
}

try {
await Promise.all(queries);
tx.commit();
done();
}
catch(e) {
tx.rollback();
done(e);
}
};

0 comments on commit a6abe60

Please sign in to comment.