From 392e632d1f09110e576a5aecc328b2632386ea66 Mon Sep 17 00:00:00 2001 From: Nick Oliver Date: Fri, 5 Apr 2024 15:14:15 -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 04a9b7c71..9b32ecf10 100644 --- a/src/server/utils/watchLocalModules.js +++ b/src/server/utils/watchLocalModules.js @@ -81,23 +81,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() { @@ -105,7 +88,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 @@ -138,7 +121,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)) ); });