This repository has been archived by the owner on Nov 3, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: concurrent file uploads (#205)
The current implementation upload files one by one, which doesn't perform really well for files smaller than 5MB. With that change, files can be uploaded in parallel, allowing faster upload speeds.
- Loading branch information
1 parent
187b08e
commit 43bc224
Showing
8 changed files
with
96 additions
and
34 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
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,35 @@ | ||
const queue = require('async/queue'); | ||
|
||
const config = require('../../config'); | ||
const logger = require('../../config/logger'); | ||
|
||
module.exports = function({ uploadFile }) { | ||
// Expand the data from the task to perform a file upload | ||
async function processFileTask(task) { | ||
await uploadFile(task.transferOrBoard, task.file, task.content); | ||
} | ||
|
||
// Create a queue object with a concurrency defined in the configuration. | ||
// processFileTask will be executed for every task. | ||
const uploadQueue = queue(processFileTask, config.concurrency); | ||
|
||
return function enqueueFileTask(task) { | ||
return new Promise((resolve, reject) => { | ||
const fileName = task.file.name; | ||
|
||
logger.debug(`[${fileName}] Queuing file to be uploaded.`); | ||
|
||
uploadQueue.push(task, (error) => { | ||
if (error) { | ||
logger.debug(`[${fileName}] Queue: file failed to upload.`); | ||
|
||
return reject(error); | ||
} | ||
|
||
logger.debug(`[${fileName}] Queue: file upload complete.`); | ||
|
||
resolve(task); | ||
}); | ||
}); | ||
}; | ||
}; |
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
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