From 43beb6fa37eb3fdf6975a293487f868020029dea Mon Sep 17 00:00:00 2001 From: csmig Date: Tue, 11 Jun 2024 07:57:44 -0400 Subject: [PATCH] refactor for readability --- lib/scan.js | 54 ++++++++++++++++++++++++++--------------------------- 1 file changed, 26 insertions(+), 28 deletions(-) diff --git a/lib/scan.js b/lib/scan.js index 9727fe0..70becd0 100644 --- a/lib/scan.js +++ b/lib/scan.js @@ -32,37 +32,35 @@ async function startScanner() { const discoveredFiles = new Set() // in memory set of files discovered in the current scan try { - //if the parseQueue and cargoQueue are empty, start a scan - if (parseQueue.length == 0 && cargoQueue.length == 0) { - logger.info({ component, message: `queue empty, starting scan` }) + //if the parseQueue and cargoQueue are not empty, skip the scan + if (parseQueue.length || cargoQueue.length) { + logger.info({ component, message: `scan skipped, queues not empty`, parseQueueSize: parseQueue.length, cargoQueueSize: cargoQueue.length }) + return + } // scan the path for files - const stream = fg.stream([`${options.path}/**/*.ckl`, `${options.path}/**/*.xml`, `${options.path}/**/*.cklb`], { - dot: !options.ignoreDot, - suppressErrors: true, - ignore: options.ignoreGlob ?? [] - }) - logger.info({ component, message: `scan started`, path: options.path }) - // for each file discovered - for await (const entry of stream) { - discoveredFiles.add(entry) - logger.verbose({ component, message: `discovered file`, file: entry }) - // check if the file is in the history - if (historySet.has(entry)) { - logger.verbose({component, message: `history match`, file: entry}) - } - // if the file is not in the history, add it to the in memory history set. - else { - parseQueue.push(entry) - logger.info({component, message: `queued for parsing`, file: entry}) - } + const stream = fg.stream([`${options.path}/**/*.ckl`, `${options.path}/**/*.xml`, `${options.path}/**/*.cklb`], { + dot: !options.ignoreDot, + suppressErrors: true, + ignore: options.ignoreGlob ?? [] + }) + logger.info({ component, message: `scan started`, path: options.path }) + // for each file discovered + for await (const entry of stream) { + discoveredFiles.add(entry) + logger.verbose({ component, message: `discovered file`, file: entry }) + // check if the file is in the history + if (historySet.has(entry)) { + logger.verbose({component, message: `history match`, file: entry}) + } + // if the file is not in the history, add it to the in memory history set. + else { + parseQueue.push(entry) + logger.info({component, message: `queued for parsing`, file: entry}) } - //Remove stale files: those in historySet but not found in the current scan - removeStaleFiles(discoveredFiles) - logger.info({ component, message: `scan ended`, path: options.path }) - } - else { - logger.info({ component, message: `scan skipped, queue not empty. parseQueue: ${parseQueue.length} cargoQueue: ${cargoQueue.length}` }) } + //Remove stale files: those in historySet but not found in the current scan + removeStaleFiles(discoveredFiles) + logger.info({ component, message: `scan ended`, path: options.path }) } catch (e) { logger.error({ component, error: serializeError(e) })