@@ -39,7 +39,6 @@ class Watcher extends EventEmitter {
3939 this . directoryWatcher = directoryWatcher ;
4040 this . path = filePath ;
4141 this . startTime = startTime && + startTime ;
42- this . _cachedTimeInfoEntries = undefined ;
4342 }
4443
4544 checkStartTime ( mtime , initial ) {
@@ -130,8 +129,6 @@ class DirectoryWatcher extends EventEmitter {
130129 }
131130
132131 setMissing ( itemPath , initial , type ) {
133- this . _cachedTimeInfoEntries = undefined ;
134-
135132 if ( this . initialScan ) {
136133 this . initialScanRemoved . add ( itemPath ) ;
137134 }
@@ -200,7 +197,6 @@ class DirectoryWatcher extends EventEmitter {
200197 accuracy,
201198 timestamp : mtime
202199 } ) ;
203- this . _cachedTimeInfoEntries = undefined ;
204200
205201 if ( ! old ) {
206202 const key = withoutCase ( filePath ) ;
@@ -243,7 +239,6 @@ class DirectoryWatcher extends EventEmitter {
243239 if ( ! old ) {
244240 const now = Date . now ( ) ;
245241
246- this . _cachedTimeInfoEntries = undefined ;
247242 if ( this . nestedWatching ) {
248243 this . createNestedWatcher ( directoryPath ) ;
249244 } else {
@@ -274,7 +269,6 @@ class DirectoryWatcher extends EventEmitter {
274269 createNestedWatcher ( directoryPath ) {
275270 const watcher = this . watcherManager . watchDirectory ( directoryPath , 1 ) ;
276271 watcher . on ( "change" , ( filePath , mtime , type , initial ) => {
277- this . _cachedTimeInfoEntries = undefined ;
278272 this . forEachWatcher ( this . path , w => {
279273 if ( ! initial || w . checkStartTime ( mtime , initial ) ) {
280274 w . emit ( "change" , filePath , mtime , type , initial ) ;
@@ -287,7 +281,6 @@ class DirectoryWatcher extends EventEmitter {
287281 setNestedWatching ( flag ) {
288282 if ( this . nestedWatching !== ! ! flag ) {
289283 this . nestedWatching = ! ! flag ;
290- this . _cachedTimeInfoEntries = undefined ;
291284 if ( this . nestedWatching ) {
292285 for ( const directory of this . directories . keys ( ) ) {
293286 this . createNestedWatcher ( directory ) ;
@@ -425,7 +418,6 @@ class DirectoryWatcher extends EventEmitter {
425418 }
426419 }
427420 this . lastWatchEvent = Date . now ( ) ;
428- this . _cachedTimeInfoEntries = undefined ;
429421 if ( ! stats ) {
430422 this . setMissing ( filePath , false , eventType ) ;
431423 } else if ( stats . isDirectory ( ) ) {
@@ -709,48 +701,47 @@ class DirectoryWatcher extends EventEmitter {
709701 return obj ;
710702 }
711703
712- getTimeInfoEntries ( ) {
713- if ( this . _cachedTimeInfoEntries !== undefined )
714- return this . _cachedTimeInfoEntries ;
715- const map = new Map ( ) ;
704+ collectTimeInfoEntries ( fileTimestamps , directoryTimestamps ) {
716705 let safeTime = this . lastWatchEvent ;
717706 for ( const [ file , entry ] of this . files ) {
718707 fixupEntryAccuracy ( entry ) ;
719708 safeTime = Math . max ( safeTime , entry . safeTime ) ;
720- map . set ( file , entry ) ;
709+ fileTimestamps . set ( file , entry ) ;
721710 }
722711 if ( this . nestedWatching ) {
723712 for ( const w of this . directories . values ( ) ) {
724- const timeInfoEntries = w . directoryWatcher . getTimeInfoEntries ( ) ;
725- for ( const [ file , entry ] of timeInfoEntries ) {
726- if ( entry ) {
727- safeTime = Math . max ( safeTime , entry . safeTime ) ;
728- }
729- map . set ( file , entry ) ;
730- }
713+ safeTime = Math . max (
714+ safeTime ,
715+ w . directoryWatcher . collectTimeInfoEntries (
716+ fileTimestamps ,
717+ directoryTimestamps ,
718+ safeTime
719+ )
720+ ) ;
731721 }
732- map . set ( this . path , {
722+ fileTimestamps . set ( this . path , EXISTANCE_ONLY_TIME_ENTRY ) ;
723+ directoryTimestamps . set ( this . path , {
733724 safeTime
734725 } ) ;
735726 } else {
736727 for ( const dir of this . directories . keys ( ) ) {
737728 // No additional info about this directory
738- map . set ( dir , EXISTANCE_ONLY_TIME_ENTRY ) ;
729+ directoryTimestamps . set ( dir , EXISTANCE_ONLY_TIME_ENTRY ) ;
739730 }
740- map . set ( this . path , EXISTANCE_ONLY_TIME_ENTRY ) ;
731+ fileTimestamps . set ( this . path , EXISTANCE_ONLY_TIME_ENTRY ) ;
732+ directoryTimestamps . set ( this . path , EXISTANCE_ONLY_TIME_ENTRY ) ;
741733 }
742734 if ( ! this . initialScan ) {
743735 for ( const watchers of this . watchers . values ( ) ) {
744736 for ( const watcher of watchers ) {
745737 const path = watcher . path ;
746- if ( ! map . has ( path ) ) {
747- map . set ( path , null ) ;
738+ if ( ! directoryTimestamps . has ( path ) ) {
739+ directoryTimestamps . set ( path , null ) ;
748740 }
749741 }
750742 }
751- this . _cachedTimeInfoEntries = map ;
752743 }
753- return map ;
744+ return safeTime ;
754745 }
755746
756747 close ( ) {
0 commit comments