@@ -40,10 +40,13 @@ public FileDatabaseBuilder(
40
40
_progressTrackerFactory = progressTrackerFactory ;
41
41
}
42
42
43
- public IFileDatabaseSnapshot Build ( IFileDatabaseSnapshot previousDatabase , FileSystemSnapshot newSnapshot ,
44
- FullPathChanges fullPathChanges ,
45
- Action onLoading , Action onLoaded , Action < IFileDatabaseSnapshot > onIntermadiateResult ,
46
- CancellationToken cancellationToken ) {
43
+ public IFileDatabaseSnapshot Build ( IFileDatabaseSnapshot previousDatabase ,
44
+ FileSystemSnapshot newSnapshot ,
45
+ FullPathChanges fullPathChanges ,
46
+ Action onLoading ,
47
+ Action onLoaded ,
48
+ Action < IFileDatabaseSnapshot > onIntermadiateResult ,
49
+ CancellationToken cancellationToken ) {
47
50
using ( new TimeElapsedLogger ( "Building file database from previous one and file system tree snapshot" ,
48
51
cancellationToken , InfoLogger . Instance ) ) {
49
52
using ( var progress = _progressTrackerFactory . CreateIndeterminateTracker ( ) ) {
@@ -94,10 +97,12 @@ public IFileDatabaseSnapshot Build(IFileDatabaseSnapshot previousDatabase, FileS
94
97
}
95
98
96
99
public IFileDatabaseSnapshot BuildWithChangedFiles ( IFileDatabaseSnapshot previousFileDatabaseSnapshot ,
97
- FileSystemSnapshot fileSystemSnapshot , IEnumerable < ProjectFileName > changedFiles ,
98
- Action onLoading , Action onLoaded , Action < IFileDatabaseSnapshot > onIntermadiateResult ,
99
- CancellationToken cancellationToken ) {
100
-
100
+ FileSystemSnapshot fileSystemSnapshot ,
101
+ IEnumerable < ProjectFileName > changedFiles ,
102
+ Action onLoading ,
103
+ Action onLoaded ,
104
+ Action < IFileDatabaseSnapshot > onIntermadiateResult ,
105
+ CancellationToken cancellationToken ) {
101
106
using ( new TimeElapsedLogger ( "Building file database from previous one and list of changed files" ,
102
107
cancellationToken , InfoLogger . Instance ) ) {
103
108
Invariants . Assert ( previousFileDatabaseSnapshot is FileDatabaseSnapshot ) ;
@@ -129,8 +134,9 @@ public IFileDatabaseSnapshot BuildWithChangedFiles(IFileDatabaseSnapshot previou
129
134
}
130
135
}
131
136
132
- private FileDatabaseSnapshot CreateFileDatabase ( FileSystemEntities entities , bool notifyProgress ,
133
- CancellationToken cancellationToken ) {
137
+ private FileDatabaseSnapshot CreateFileDatabase ( FileSystemEntities entities ,
138
+ bool notifyProgress ,
139
+ CancellationToken cancellationToken ) {
134
140
cancellationToken . ThrowIfCancellationRequested ( ) ;
135
141
using ( new TimeElapsedLogger ( "Freezing file database state" , cancellationToken ) ) {
136
142
var progress = notifyProgress ? _progressTrackerFactory . CreateIndeterminateTracker ( ) : null ;
@@ -250,7 +256,7 @@ private class FileSystemEntities {
250
256
}
251
257
252
258
private FileSystemEntities ComputeFileSystemEntities ( FileSystemSnapshot snapshot ,
253
- CancellationToken cancellationToken ) {
259
+ CancellationToken cancellationToken ) {
254
260
using ( new TimeElapsedLogger ( "Computing tables of directory names and file names from FileSystemTree" ,
255
261
cancellationToken ) ) {
256
262
@@ -312,8 +318,9 @@ private class FileContentsLoadingContext {
312
318
public PartialProgressReporter PartialProgressReporter ;
313
319
}
314
320
315
- private void LoadFileContents ( FileSystemEntities entities , FileContentsLoadingContext loadingContext ,
316
- CancellationToken cancellationToken ) {
321
+ private void LoadFileContents ( FileSystemEntities entities ,
322
+ FileContentsLoadingContext loadingContext ,
323
+ CancellationToken cancellationToken ) {
317
324
using ( new TimeElapsedLogger ( "Loading file contents from disk" , cancellationToken ) ) {
318
325
using ( var progress = _progressTrackerFactory . CreateTracker ( entities . Files . Count ) ) {
319
326
entities . Files . AsParallelWrapper ( ) . ForAll ( fileEntry => {
@@ -358,7 +365,8 @@ private void LoadFileContents(FileSystemEntities entities, FileContentsLoadingCo
358
365
/// and <see cref="SlimHashTable{TKey,TValue}"/> behave that way.</para>
359
366
/// </summary>
360
367
private static void DangerousUpdateFileSystemEntitiesEntry ( FileSystemEntities entities ,
361
- KeyValuePair < FileName , ProjectFileData > fileEntry , FileContents contents ) {
368
+ KeyValuePair < FileName , ProjectFileData > fileEntry ,
369
+ FileContents contents ) {
362
370
entities . Files [ fileEntry . Key ] = fileEntry . Value . WithContents ( contents ) ;
363
371
}
364
372
@@ -374,21 +382,21 @@ private static void DangerousUpdateFileSystemEntitiesEntry(FileSystemEntities en
374
382
/// 2) is verified because the two possible implementations, <see cref="Dictionary{TKey,TValue}"/>
375
383
/// and <see cref="SlimHashTable{TKey,TValue}"/> behave that way.</para>
376
384
/// </summary>
377
- private static void DangerousUpdateFileTableEntry ( FileDatabaseSnapshot fileDatabase , FileName fileName ,
378
- FileContents newContents ) {
385
+ private static void DangerousUpdateFileTableEntry ( FileDatabaseSnapshot fileDatabase ,
386
+ FileName fileName ,
387
+ FileContents newContents ) {
379
388
fileDatabase . Files [ fileName ] = new FileWithContents ( fileName , newContents ) ;
380
389
}
381
390
382
- private FileContents LoadSingleFileContents (
383
- FileSystemEntities entities ,
384
- FileContentsLoadingContext loadingContext ,
385
- ProjectFileData projectFileData ) {
386
-
391
+ private FileContents LoadSingleFileContents ( FileSystemEntities entities ,
392
+ FileContentsLoadingContext loadingContext ,
393
+ ProjectFileData projectFileData ) {
387
394
var fileName = projectFileData . FileName ;
388
- var oldFileData = loadingContext . OldFileDatabaseSnapshot . Files . GetValueType ( fileName ) ;
395
+ var file = loadingContext . OldFileDatabaseSnapshot . Files . GetValueType ( fileName ) ;
389
396
390
- // If the file was never loaded before, just load it
391
- if ( oldFileData == null || oldFileData . Value . Contents == null ) {
397
+ // If the file was never loaded before, just load it (after performing a
398
+ // "isSearchable" check).
399
+ if ( file ? . Contents == null ) {
392
400
return LoadSingleFileContentsWorker ( loadingContext , projectFileData ) ;
393
401
}
394
402
@@ -413,17 +421,15 @@ private FileContents LoadSingleFileContents(
413
421
414
422
// If the file has not changed since the previous snapshot, we can re-use
415
423
// the former file contents snapshot.
416
- if ( IsFileContentsUpToDate ( entities , loadingContext . FullPathChanges , oldFileData . Value ) ) {
417
- return oldFileData . Value . Contents ;
424
+ if ( IsFileContentsUpToDate ( entities , loadingContext . FullPathChanges , file . Value ) ) {
425
+ return file . Value . Contents ;
418
426
}
419
427
420
428
return LoadSingleFileContentsWorker ( loadingContext , projectFileData ) ;
421
429
}
422
430
423
- private FileContents LoadSingleFileContentsWorker (
424
- FileContentsLoadingContext loadingContext ,
425
- ProjectFileData projectFileData ) {
426
-
431
+ private FileContents LoadSingleFileContentsWorker ( FileContentsLoadingContext loadingContext ,
432
+ ProjectFileData projectFileData ) {
427
433
// If project configuration has not changed, the file is still not
428
434
// searchable, irrelevant to calling "IsSearchable".
429
435
if ( loadingContext . FullPathChanges != null ) {
@@ -434,8 +440,9 @@ private FileContents LoadSingleFileContentsWorker(
434
440
}
435
441
436
442
// This is an expensive call, hopefully avoided by the code above.
437
- if ( ! projectFileData . IsSearchable )
443
+ if ( ! projectFileData . IsSearchable ) {
438
444
return null ;
445
+ }
439
446
440
447
loadingContext . PartialProgressReporter . ReportProgress ( ) ;
441
448
@@ -449,8 +456,9 @@ private FileContents LoadSingleFileContentsWorker(
449
456
return fileContents ;
450
457
}
451
458
452
- private bool IsFileContentsUpToDate ( FileSystemEntities entities , FullPathChanges fullPathChanges ,
453
- FileWithContents existingFileWithContents ) {
459
+ private bool IsFileContentsUpToDate ( FileSystemEntities entities ,
460
+ FullPathChanges fullPathChanges ,
461
+ FileWithContents existingFileWithContents ) {
454
462
Invariants . Assert ( existingFileWithContents . Contents != null ) ;
455
463
456
464
var fullPath = existingFileWithContents . FileName . FullPath ;
@@ -459,9 +467,12 @@ private bool IsFileContentsUpToDate(FileSystemEntities entities, FullPathChanges
459
467
// We don't get file change events for file in symlinks, so we can't
460
468
// rely on fullPathChanges contents for our heuristic of avoiding file
461
469
// system access.
462
- if ( ! FileDatabaseSnapshot . IsContainedInSymLinkHelper ( entities . Directories , existingFileWithContents . FileName ) ) {
463
- return fullPathChanges . ShouldSkipLoadFileContents ( fullPath ) ;
464
- }
470
+ // Actually, since we cannot reliable detect changes in symlinks, we enable this
471
+ // optimization anyways, as we rely on the user to manually refresh the index
472
+ // (that results in a "null" value for fullPathChanges)
473
+ //if (!FileDatabaseSnapshot.IsContainedInSymLinkHelper(entities.Directories, existingFileWithContents.FileName)) {
474
+ return fullPathChanges . ShouldSkipLoadFileContents ( fullPath ) ;
475
+ //}
465
476
}
466
477
467
478
// Do the "expensive" check by going to the file system.
0 commit comments