mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
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.
This commit is contained in:
parent
71497367ef
commit
fcbe8f44ea
@ -1049,33 +1049,37 @@ class ProjectFileInvalidator {
|
||||
assert(packagesPath != null);
|
||||
|
||||
if (lastCompiled == null) {
|
||||
// Initial load.
|
||||
assert(urisToMonitor.isEmpty);
|
||||
return <Uri>[];
|
||||
}
|
||||
|
||||
final List<Uri> invalidatedFiles = <Uri>[];
|
||||
int scanned = 0;
|
||||
final Stopwatch stopwatch = Stopwatch()..start();
|
||||
for (Uri uri in urisToMonitor) {
|
||||
if ((platform.isWindows && uri.path.contains(_pubCachePathWindows))
|
||||
|| uri.path.contains(_pubCachePathLinuxAndMac)) {
|
||||
// Don't watch pub cache directories to speed things up a little.
|
||||
continue;
|
||||
}
|
||||
|
||||
final List<Uri> urisToScan = <Uri>[
|
||||
// Don't watch pub cache directories to speed things up a little.
|
||||
...urisToMonitor.where(_isNotInPubCache),
|
||||
|
||||
// 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(
|
||||
uri.toFilePath(windows: platform.isWindows)).modified;
|
||||
scanned++;
|
||||
if (updatedAt != null && updatedAt.isAfter(lastCompiled)) {
|
||||
invalidatedFiles.add(uri);
|
||||
}
|
||||
}
|
||||
// We need to check the .packages file too since it is not used in compilation.
|
||||
final DateTime packagesUpdatedAt = fs.statSync(packagesPath).modified;
|
||||
if (packagesUpdatedAt != null && packagesUpdatedAt.isAfter(lastCompiled)) {
|
||||
invalidatedFiles.add(fs.file(packagesPath).uri);
|
||||
scanned++;
|
||||
}
|
||||
printTrace('Scanned through $scanned files in ${stopwatch.elapsedMilliseconds}ms');
|
||||
printTrace(
|
||||
'Scanned through ${urisToScan.length} files in '
|
||||
'${stopwatch.elapsedMilliseconds}ms',
|
||||
);
|
||||
return invalidatedFiles;
|
||||
}
|
||||
|
||||
static bool _isNotInPubCache(Uri uri) {
|
||||
return !(platform.isWindows && uri.path.contains(_pubCachePathWindows))
|
||||
&& !uri.path.contains(_pubCachePathLinuxAndMac);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user