@@ -17,6 +17,8 @@ import { DateFallback } from '../DateTime/DateFallback';
1717import { getSettings } from '../Config/Settings' ;
1818import { Lazy } from '../lib/Lazy' ;
1919import { Logger , logging } from '../lib/logging' ;
20+ import { PerformanceTracker } from '../lib/PerformanceTracker' ;
21+ import { GlobalFilter } from '../Config/GlobalFilter' ;
2022import type { TasksEvents } from './TasksEvents' ;
2123import { FileParser } from './FileParser' ;
2224
@@ -31,9 +33,11 @@ export class Cache {
3133
3234 private readonly metadataCache : MetadataCache ;
3335 private readonly metadataCacheEventReferences : EventRef [ ] ;
36+
3437 private readonly vault : Vault ;
3538 private readonly workspace : Workspace ;
3639 private readonly vaultEventReferences : EventRef [ ] ;
40+
3741 private readonly events : TasksEvents ;
3842 private readonly eventsEventReferences : EventRef [ ] ;
3943
@@ -72,9 +76,11 @@ export class Cache {
7276
7377 this . metadataCache = metadataCache ;
7478 this . metadataCacheEventReferences = [ ] ;
79+
7580 this . vault = vault ;
7681 this . workspace = workspace ;
7782 this . vaultEventReferences = [ ] ;
83+
7884 this . events = events ;
7985 this . eventsEventReferences = [ ] ;
8086
@@ -227,11 +233,20 @@ export class Cache {
227233 handler ( { tasks : this . tasks , state : this . state } ) ;
228234 } ) ;
229235 this . eventsEventReferences . push ( requestReference ) ;
236+
237+ // The caller is responsible for debouncing this:
238+ const reloadVaultReference = this . events . onReloadVault ( async ( ) => await this . loadVault ( ) ) ;
239+ this . eventsEventReferences . push ( reloadVaultReference ) ;
230240 }
231241
232242 private loadVault ( ) : Promise < void > {
233243 this . logger . debug ( 'Cache.loadVault()' ) ;
234244 return this . tasksMutex . runExclusive ( async ( ) => {
245+ const measureLoad = new PerformanceTracker (
246+ `Loading vault with global filter '${ GlobalFilter . getInstance ( ) . get ( ) } '` ,
247+ ) ;
248+ measureLoad . start ( ) ;
249+
235250 this . state = State . Initializing ;
236251 this . logger . debug ( 'Cache.loadVault(): state = Initializing' ) ;
237252
@@ -244,6 +259,11 @@ export class Cache {
244259 // TODO Why is this displayed twice:
245260 this . logger . debug ( 'Cache.loadVault(): state = Warm' ) ;
246261
262+ // Report that we have finished loading before notifying subscribers,
263+ // so we don't double-count things like redrawing search results.
264+ // These have their own timer code.
265+ measureLoad . finish ( ) ;
266+
247267 // Notify that the cache is now warm:
248268 this . notifySubscribers ( ) ;
249269 } ) ;
0 commit comments