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
cae7cb7
commit a6abe60
Showing
6 changed files
with
2,948 additions
and
45 deletions.
There are no files selected for viewing
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
51 changes: 51 additions & 0 deletions
51
benchmark/doxbee-sequential/promises-native-async-await.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,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); | ||
} | ||
}; |
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,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); | ||
} | ||
}; |
Oops, something went wrong.