Make ProjectFileInvalidator.findInvalidated able to use the async FileStat.stat (#42028)
Empirical measurements indicate on the network file system we use internally, using `FileStat.stat` on thousands of files is much faster than using `FileStat.statSync`. (It can be slower for files on a local SSD, however.) Add a flag to `ProjectFileInvalidator.findInvalidated` to let it use `FileStat.stat` instead of `FileStat.statSync` when scanning for modified files. This can be enabled by overriding `HotRunnerConfig`. I considered creating a separate, asynchronous version of `findInvalidated`, but that led to more code duplication than I liked, and it would be harder to avoid drift between the versions.
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
import 'package:file/memory.dart';
|
||||
import 'package:flutter_tools/src/base/file_system.dart';
|
||||
import 'package:flutter_tools/src/run_hot.dart';
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
import '../src/common.dart';
|
||||
import '../src/context.dart';
|
||||
@@ -14,43 +15,53 @@ final DateTime inFuture = DateTime.now().add(const Duration(days: 100));
|
||||
|
||||
void main() {
|
||||
group('ProjectFileInvalidator', () {
|
||||
testUsingContext('No last compile', () async {
|
||||
expect(
|
||||
ProjectFileInvalidator.findInvalidated(
|
||||
lastCompiled: null,
|
||||
urisToMonitor: <Uri>[],
|
||||
packagesPath: '',
|
||||
),
|
||||
isEmpty,
|
||||
);
|
||||
});
|
||||
|
||||
testUsingContext('Empty project', () async {
|
||||
expect(
|
||||
ProjectFileInvalidator.findInvalidated(
|
||||
lastCompiled: inFuture,
|
||||
urisToMonitor: <Uri>[],
|
||||
packagesPath: '',
|
||||
),
|
||||
isEmpty,
|
||||
);
|
||||
}, overrides: <Type, Generator>{
|
||||
FileSystem: () => MemoryFileSystem(),
|
||||
ProcessManager: () => FakeProcessManager(<FakeCommand>[]),
|
||||
});
|
||||
|
||||
testUsingContext('Non-existent files are ignored', () async {
|
||||
expect(
|
||||
ProjectFileInvalidator.findInvalidated(
|
||||
lastCompiled: inFuture,
|
||||
urisToMonitor: <Uri>[Uri.parse('/not-there-anymore'),],
|
||||
packagesPath: '',
|
||||
),
|
||||
isEmpty,
|
||||
);
|
||||
}, overrides: <Type, Generator>{
|
||||
FileSystem: () => MemoryFileSystem(),
|
||||
ProcessManager: () => FakeProcessManager(<FakeCommand>[]),
|
||||
});
|
||||
_testProjectFileInvalidator(asyncScanning: false);
|
||||
});
|
||||
group('ProjectFileInvalidator (async scanning)', () {
|
||||
_testProjectFileInvalidator(asyncScanning: true);
|
||||
});
|
||||
}
|
||||
|
||||
void _testProjectFileInvalidator({@required bool asyncScanning}) {
|
||||
testUsingContext('No last compile', () async {
|
||||
expect(
|
||||
await ProjectFileInvalidator.findInvalidated(
|
||||
lastCompiled: null,
|
||||
urisToMonitor: <Uri>[],
|
||||
packagesPath: '',
|
||||
asyncScanning: asyncScanning,
|
||||
),
|
||||
isEmpty,
|
||||
);
|
||||
});
|
||||
|
||||
testUsingContext('Empty project', () async {
|
||||
expect(
|
||||
await ProjectFileInvalidator.findInvalidated(
|
||||
lastCompiled: inFuture,
|
||||
urisToMonitor: <Uri>[],
|
||||
packagesPath: '',
|
||||
asyncScanning: asyncScanning,
|
||||
),
|
||||
isEmpty,
|
||||
);
|
||||
}, overrides: <Type, Generator>{
|
||||
FileSystem: () => MemoryFileSystem(),
|
||||
ProcessManager: () => FakeProcessManager(<FakeCommand>[]),
|
||||
});
|
||||
|
||||
testUsingContext('Non-existent files are ignored', () async {
|
||||
expect(
|
||||
await ProjectFileInvalidator.findInvalidated(
|
||||
lastCompiled: inFuture,
|
||||
urisToMonitor: <Uri>[Uri.parse('/not-there-anymore'),],
|
||||
packagesPath: '',
|
||||
asyncScanning: asyncScanning,
|
||||
),
|
||||
isEmpty,
|
||||
);
|
||||
}, overrides: <Type, Generator>{
|
||||
FileSystem: () => MemoryFileSystem(),
|
||||
ProcessManager: () => FakeProcessManager(<FakeCommand>[]),
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user