From acefc8f96af7058f3e46255ecf6166b208747d25 Mon Sep 17 00:00:00 2001 From: Nick Oliver Date: Thu, 4 Apr 2024 11:46:41 -0700 Subject: [PATCH] refactor(server): remove deduped fs.stat from watchLocalModules --- src/server/utils/watchLocalModules.js | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-) diff --git a/src/server/utils/watchLocalModules.js b/src/server/utils/watchLocalModules.js index 9f695c49b..4f40d43e1 100644 --- a/src/server/utils/watchLocalModules.js +++ b/src/server/utils/watchLocalModules.js @@ -87,23 +87,6 @@ export default function watchLocalModules() { const staticsDirectoryPath = path.resolve(__dirname, '../../../static'); const moduleDirectory = path.join(staticsDirectoryPath, 'modules'); - // this may be an over-optimization in that it may be more overhead than it saves - const stating = new Map(); - function dedupedStat(filePath) { - if (!stating.has(filePath)) { - stating.set( - filePath, - fs.stat(filePath) - .then((fileStat) => { - stating.delete(filePath); - return fileStat; - }) - ); - } - - return stating.get(filePath); - } - const checkForNoWrites = new Map(); let nextWriteCheck = null; async function writesFinishWatcher() { @@ -111,7 +94,7 @@ export default function watchLocalModules() { await Promise.allSettled( [...checkForNoWrites.entries()].map(async ([holocronEntrypoint, previousStat]) => { - const currentStat = await dedupedStat(path.join(moduleDirectory, holocronEntrypoint)); + const currentStat = await fs.stat(path.join(moduleDirectory, holocronEntrypoint)); if ( currentStat.mtimeMs !== previousStat.mtimeMs || currentStat.size !== previousStat.size @@ -144,7 +127,7 @@ export default function watchLocalModules() { const statsToWait = []; holocronEntrypoints.forEach((holocronEntrypoint) => { statsToWait.push( - dedupedStat(path.join(moduleDirectory, holocronEntrypoint)) + fs.stat(path.join(moduleDirectory, holocronEntrypoint)) .then((stat) => currentStats.set(holocronEntrypoint, stat)) ); });