Unverified Commit fcbe8f44 authored by James D. Lin's avatar James D. Lin Committed by GitHub

Restructure ProjectFileInvalidator.findInvalidated a bit (#42008)

Restructure ProjectFileInvalidator.findInvalidated a bit

I plan to modify `ProjectFileInvalidator.findInvalidated` to allow
it to use `FileStat.stat` instead of `FileStat.statSync`.
Restructure `findInvalidated` a bit so that `FileStat.statSync` is
called in only one place.

Note that this change now always counts the `.packages` file as one
of the files scanned, even if it does not exist.  I think that this
is okay since it more accurately reflects the number of times that we
hit the filesystem with `stat()`, and it is consistent with how other
files are counted.
parent 71497367
...@@ -1049,33 +1049,37 @@ class ProjectFileInvalidator { ...@@ -1049,33 +1049,37 @@ class ProjectFileInvalidator {
assert(packagesPath != null); assert(packagesPath != null);
if (lastCompiled == null) { if (lastCompiled == null) {
// Initial load.
assert(urisToMonitor.isEmpty); assert(urisToMonitor.isEmpty);
return <Uri>[]; return <Uri>[];
} }
final List<Uri> invalidatedFiles = <Uri>[];
int scanned = 0;
final Stopwatch stopwatch = Stopwatch()..start(); final Stopwatch stopwatch = Stopwatch()..start();
for (Uri uri in urisToMonitor) {
if ((platform.isWindows && uri.path.contains(_pubCachePathWindows)) final List<Uri> urisToScan = <Uri>[
|| uri.path.contains(_pubCachePathLinuxAndMac)) { // Don't watch pub cache directories to speed things up a little.
// Don't watch pub cache directories to speed things up a little. ...urisToMonitor.where(_isNotInPubCache),
continue;
} // We need to check the .packages file too since it is not used in compilation.
fs.file(packagesPath).uri,
];
final List<Uri> invalidatedFiles = <Uri>[];
for (final Uri uri in urisToScan) {
final DateTime updatedAt = fs.statSync( final DateTime updatedAt = fs.statSync(
uri.toFilePath(windows: platform.isWindows)).modified; uri.toFilePath(windows: platform.isWindows)).modified;
scanned++;
if (updatedAt != null && updatedAt.isAfter(lastCompiled)) { if (updatedAt != null && updatedAt.isAfter(lastCompiled)) {
invalidatedFiles.add(uri); invalidatedFiles.add(uri);
} }
} }
// We need to check the .packages file too since it is not used in compilation. printTrace(
final DateTime packagesUpdatedAt = fs.statSync(packagesPath).modified; 'Scanned through ${urisToScan.length} files in '
if (packagesUpdatedAt != null && packagesUpdatedAt.isAfter(lastCompiled)) { '${stopwatch.elapsedMilliseconds}ms',
invalidatedFiles.add(fs.file(packagesPath).uri); );
scanned++;
}
printTrace('Scanned through $scanned files in ${stopwatch.elapsedMilliseconds}ms');
return invalidatedFiles; return invalidatedFiles;
} }
static bool _isNotInPubCache(Uri uri) {
return !(platform.isWindows && uri.path.contains(_pubCachePathWindows))
&& !uri.path.contains(_pubCachePathLinuxAndMac);
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment