From d917129cb55366041c249804a0be4f6e84470a3a Mon Sep 17 00:00:00 2001 From: Rishi Ghan Date: Thu, 14 Apr 2022 12:35:24 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20Optimizing=20chokidar=20listener?= =?UTF-8?q?s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- services/api.service.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/services/api.service.ts b/services/api.service.ts index 7cee25c..b22b5a4 100644 --- a/services/api.service.ts +++ b/services/api.service.ts @@ -125,10 +125,10 @@ export default class ApiService extends Service { const fileWatcher = chokidar.watch( path.resolve("./comics"), { - ignored: /(^|[\/\\])\../, // ignore dotfiles + ignored: (filePath) => path.extname(filePath) === '.dctmp', persistent: true, usePolling: true, - interval: 500, + interval: 5000, ignoreInitial: true, followSymlinks: true, atomic: true, @@ -175,7 +175,7 @@ export default class ApiService extends Service { }); }; fileWatcher - .on("add", async (path, stats) => { + .once("add", async (path, stats) => { console.log("Watcher detected new files."); console.log( `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( `File ${path} has been changed. Stats: ${JSON.stringify(stats, null, 2)}` ) ) - .on("unlink", (path) => + .once("unlink", (path) => console.log(`File ${path} has been removed`) ) - .on("addDir", (path) => + .once("addDir", (path) => console.log(`Directory ${path} has been added`) ); });