From 54c4dbcbf78f5dc3a1fb02f61ff8bd138bfb8290 Mon Sep 17 00:00:00 2001 From: Ben Newman Date: Fri, 30 Jun 2017 11:28:49 -0400 Subject: [PATCH] Require opting into the behavior introduced by the previous commit. Although I think 8c70716954f8fcdd02fc0c673a39da2b7186ce2b is a good idea in practice, it altered the timing of self-tests enough to cause a number of failures, so for now that behavior will be gated behind the environment variable METEOR_WATCH_PRIORITIZE_CHANGED. --- tools/fs/safe-watcher.js | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/tools/fs/safe-watcher.js b/tools/fs/safe-watcher.js index eb5d5d667c..c71c8a4ed5 100644 --- a/tools/fs/safe-watcher.js +++ b/tools/fs/safe-watcher.js @@ -17,6 +17,10 @@ if (process.platform === "win32") { WATCHER_ENABLED = false; } +var PRIORITIZE_CHANGED = + process.env.METEOR_WATCH_PRIORITIZE_CHANGED && + JSON.parse(process.env.METEOR_WATCH_PRIORITIZE_CHANGED); + var DEFAULT_POLLING_INTERVAL = ~~process.env.METEOR_WATCH_POLLING_INTERVAL_MS || 5000; @@ -37,7 +41,17 @@ const entriesByIno = new Map; // Set of paths for which a change event has been fired, watched with // watchLibrary.watch if available. This could be an LRU cache, but in // practice it should never grow large enough for that to matter. -const recentlyChanged = new Set; +const changedPaths = new Set; + +function hasPriority(absPath) { + // If we're not prioritizing changed files, then all files have + // priority, which means they should be watched with native file + // watchers if the platform supports them. If we are prioritizing + // changed files, then only changed files get priority. + return PRIORITIZE_CHANGED + ? changedPaths.has(absPath) + : true; +} function acquireWatcher(absPath, callback) { const entry = entries[absPath] || ( @@ -82,7 +96,7 @@ function startNewWatcher(absPath) { return DEFAULT_POLLING_INTERVAL; } - if (recentlyChanged.has(absPath)) { + if (hasPriority(absPath)) { return NO_WATCHER_POLLING_INTERVAL; } @@ -108,7 +122,7 @@ function startNewWatcher(absPath) { lastWatcherEventTime = 0; } else { - recentlyChanged.add(absPath); + changedPaths.add(absPath); rewatch(); } @@ -128,7 +142,7 @@ function startNewWatcher(absPath) { } function rewatch() { - if (recentlyChanged.has(absPath)) { + if (hasPriority(absPath)) { if (watcher) { // Already watching; nothing to do. return;