Skip to content
This repository has been archived by the owner on May 3, 2024. It is now read-only.

Commit

Permalink
refactor(server): remove deduped fs.stat from watchLocalModules
Browse files Browse the repository at this point in the history
  • Loading branch information
PixnBits committed Apr 4, 2024
1 parent 51aa8eb commit 7398793
Showing 1 changed file with 2 additions and 19 deletions.
21 changes: 2 additions & 19 deletions src/server/utils/watchLocalModules.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,31 +87,14 @@ 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() {
nextWriteCheck = null;

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
Expand Down Expand Up @@ -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))
);
});
Expand Down

0 comments on commit 7398793

Please sign in to comment.