From 88e3a284b78c57b9954255cd37ed0eb0383c7308 Mon Sep 17 00:00:00 2001 From: James Ketrenos Date: Sat, 29 Sep 2018 17:27:14 -0700 Subject: [PATCH] Re-load continues processing correctly Signed-off-by: James Ketrenos --- server/scanner.js | 44 +++++++++++++++++--------------------------- 1 file changed, 17 insertions(+), 27 deletions(-) diff --git a/server/scanner.js b/server/scanner.js index 1db46e9..ecefc7e 100755 --- a/server/scanner.js +++ b/server/scanner.js @@ -202,8 +202,8 @@ function processBlock(items) { }); let toProcess = processing.length, lastMessage = moment(); - console.log("Hash items to be processed: " + toProcess); - return Promise.map(processing, function(asset) { + console.log("Items to be processed: " + toProcess); + return Promise.mapSeries(processing, function(asset) { return computeHash(picturesPath + asset.album.path + asset.filename).then(function(hash) { asset.hash = hash; return asset; @@ -226,7 +226,7 @@ function processBlock(items) { "'" + asset.album.path + asset.filename + "' is a copy of " + "'" + results[0].path + results[0].filename + "'"); duplicates.push(asset); - return; + return null; } /* Even if the hash doesn't need to be updated, the entry needs to be scanned */ @@ -241,23 +241,12 @@ function processBlock(items) { }).then(function() { return asset; }); - }).then(function() { - toProcess--; - if (moment().add(-5, 'seconds') > lastMessage) { - console.log("Hash items to be processed: " + toProcess); - lastMessage = moment(); - } }); - }); - }, { - concurrency: 5 - }).catch(function(error) { - console.log("Error commiting HASH transactions"); - throw error; - }).then(function() { - let toProcess = needsProcessing.length, lastMessage = moment(); - console.log(needsProcessing.length + " assets need to have metadata extracted"); - return Promise.map(needsProcessing, function(asset) { + }).then(function(asset) { + if (!asset) { /* The processed entry is a DUPLICATE. Skip it. */ + return; + } + var path = asset.album.path, file = asset.filename, created = asset.stats.mtime, @@ -364,12 +353,6 @@ function processBlock(items) { "WHERE id=:id", { replacements: asset, }); - }).then(function() { - toProcess--; - if (moment().add(-5, 'seconds') > lastMessage) { - console.log("Items to be processed: " + toProcess); - lastMessage = moment(); - } }); }).catch(function(error) { console.error("Error reading image " + src + ": ", error); @@ -399,9 +382,16 @@ function processBlock(items) { }).catch(function() { console.warn("Continuing file processing."); }); - }, { - concurrency: 5 + }).then(function() { + toProcess--; + if (moment().add(-5, 'seconds') > lastMessage) { + console.log("Items to be processed: " + toProcess); + lastMessage = moment(); + } }); + }).catch(function(error) { + console.log("Error processing file. Continuing."); + throw error; }).then(function() { console.log("Completed processing queue. Marking " + duplicates.length + " duplicates."); let dups = [];