From 0f3551c3bd81e0025e1381a4ccd54df6c8680f5c Mon Sep 17 00:00:00 2001 From: Bobby Wibowo Date: Thu, 5 Apr 2018 17:31:07 +0700 Subject: [PATCH] Updated uploadController.js Refactored all instances of forEach() to for-loop (there were 3 instances). To be honest I kinda liked forEach() better in terms of readability, but oh well, let's aim for that likely tiny performance boost. --- controllers/uploadController.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/controllers/uploadController.js b/controllers/uploadController.js index 6432c4f..9fe08e2 100644 --- a/controllers/uploadController.js +++ b/controllers/uploadController.js @@ -251,7 +251,8 @@ uploadsController.actuallyFinishChunks = async (req, res, user, albumid) => { let iteration = 0 const infoMap = [] - files.forEach(file => { + for (let i = 0; i < files.length; i++) { + const file = files[i] const { uuid, count } = file if (!uuid || !count) { return erred(new Error('Missing UUID and/or chunks count.')) } @@ -303,7 +304,7 @@ uploadsController.actuallyFinishChunks = async (req, res, user, albumid) => { } }) }) - }) + } } uploadsController.appendToStream = async (destFileStream, chunksDirUuid, chunks) => { @@ -335,7 +336,8 @@ uploadsController.writeFilesToDb = async (req, res, user, albumid, infoMap) => { const files = [] const existingFiles = [] - infoMap.forEach(info => { + for (let i = 0; i < infoMap.length; i++) { + const info = infoMap[i] // Check if the file exists by checking hash and size const hash = crypto.createHash('md5') const stream = fs.createReadStream(info.path) @@ -382,7 +384,7 @@ uploadsController.writeFilesToDb = async (req, res, user, albumid, infoMap) => { return resolve({ files, existingFiles }) } }) - }) + } }) } @@ -409,13 +411,14 @@ uploadsController.processFilesForDisplay = async (req, res, files, existingFiles files.push(efile) } - files.forEach(file => { + for (let i = 0; i < files.length; i++) { + const file = files[i] const ext = path.extname(file.name).toLowerCase() if ((config.uploads.generateThumbnails.image && utils.imageExtensions.includes(ext)) || (config.uploads.generateThumbnails.video && utils.videoExtensions.includes(ext))) { file.thumb = `${basedomain}/thumbs/${file.name.slice(0, -ext.length)}.png` utils.generateThumbs(file) } - }) + } let albumSuccess = true if (albumid) {