🔧 Optimizing chokidar listeners

This commit is contained in:
2022-04-14 12:35:24 -07:00
parent c00ca0a3a0
commit d917129cb5

View File

@@ -125,10 +125,10 @@ export default class ApiService extends Service {
const fileWatcher = chokidar.watch( const fileWatcher = chokidar.watch(
path.resolve("./comics"), path.resolve("./comics"),
{ {
ignored: /(^|[\/\\])\../, // ignore dotfiles ignored: (filePath) => path.extname(filePath) === '.dctmp',
persistent: true, persistent: true,
usePolling: true, usePolling: true,
interval: 500, interval: 5000,
ignoreInitial: true, ignoreInitial: true,
followSymlinks: true, followSymlinks: true,
atomic: true, atomic: true,
@@ -175,7 +175,7 @@ export default class ApiService extends Service {
}); });
}; };
fileWatcher fileWatcher
.on("add", async (path, stats) => { .once("add", async (path, stats) => {
console.log("Watcher detected new files."); console.log("Watcher detected new files.");
console.log( console.log(
`File ${path} has been added with stats: ${JSON.stringify( `File ${path} has been added with stats: ${JSON.stringify(
@@ -208,15 +208,15 @@ export default class ApiService extends Service {
}); });
}); });
}) })
.on("change", (path, stats) => .once("change", (path, stats) =>
console.log( console.log(
`File ${path} has been changed. Stats: ${JSON.stringify(stats, null, 2)}` `File ${path} has been changed. Stats: ${JSON.stringify(stats, null, 2)}`
) )
) )
.on("unlink", (path) => .once("unlink", (path) =>
console.log(`File ${path} has been removed`) console.log(`File ${path} has been removed`)
) )
.on("addDir", (path) => .once("addDir", (path) =>
console.log(`Directory ${path} has been added`) console.log(`Directory ${path} has been added`)
); );
}); });