improved performance and battery usage on older devices

This commit is contained in:
2026-09-25 23:58:08 +02:00
parent ed8e52f475
commit 56a497985b
70 changed files with 1631 additions and 621 deletions
+21 -30
View File
@@ -11,13 +11,10 @@ CacheableFile _file({
bool isDirectory = false,
}) => CacheableFile(path: path, isDirectory: isDirectory, name: name);
Map<String, dynamic> _doc(ListFilesResponse listing) => {
'json': jsonEncode(listing.toJson()),
'lastupdate': 0,
};
String _payload(ListFilesResponse listing) => jsonEncode(listing.toJson());
void main() {
group('searchLocalCaches', () {
group('local cache index', () {
final root = ListFilesResponse({
_file(path: 'Documents/', name: 'Documents', isDirectory: true),
_file(path: 'Photos/', name: 'Photos', isDirectory: true),
@@ -27,51 +24,45 @@ void main() {
_file(path: 'Documents/Tax-Report.pdf', name: 'Tax-Report.pdf'),
_file(path: 'Documents/Notes.txt', name: 'Notes.txt'),
});
final docs = {
'/MarianumMobile/wd-folder-aaa': _doc(root),
'/MarianumMobile/wd-folder-bbb': _doc(documents),
'/MarianumMobile/get-room-ccc': {'json': '{}', 'lastupdate': 0},
};
final index = buildLocalCacheIndex([
_payload(root),
_payload(documents),
]);
test('matches by name case-insensitively across all caches', () async {
final hits = await searchLocalCaches('report', docs: docs);
test('matches by name case-insensitively across all caches', () {
final hits = searchLocalCacheIndex(index, 'report');
final paths = hits.map((f) => f.path).toSet();
expect(paths, {'Reports.pdf', 'Documents/Tax-Report.pdf'});
});
test('returns empty list for empty query', () async {
expect(await searchLocalCaches(' ', docs: docs), isEmpty);
test('returns empty list for empty query', () {
expect(searchLocalCacheIndex(index, ' '), isEmpty);
});
test('respects pathScope prefix', () async {
final hits = await searchLocalCaches(
test('respects pathScope prefix', () {
final hits = searchLocalCacheIndex(
index,
'report',
pathScope: ['Documents'],
docs: docs,
);
expect(hits.map((f) => f.path), ['Documents/Tax-Report.pdf']);
});
test('ignores non-folder cache documents', () async {
final hits = await searchLocalCaches('anything', docs: docs);
// Only documents starting with `wd-folder-` are scanned. The unrelated
// `get-room-ccc` doc must not crash the helper.
expect(hits, isEmpty);
test('skips payloads that are not folder listings', () {
expect(buildLocalCacheIndex(['not json', '{"foo": 1}']), isEmpty);
});
test('deduplicates entries that appear in multiple cached folders',
() async {
test('deduplicates entries that appear in multiple cached folders', () {
final shared = _file(
path: 'Documents/Tax-Report.pdf',
name: 'Tax-Report.pdf',
);
final dedupRoot = ListFilesResponse({shared});
final dedupDocs = {
'/MarianumMobile/wd-folder-aaa': _doc(dedupRoot),
'/MarianumMobile/wd-folder-bbb': _doc(dedupRoot),
};
final hits = await searchLocalCaches('tax', docs: dedupDocs);
expect(hits, hasLength(1));
final dedupIndex = buildLocalCacheIndex([
_payload(dedupRoot),
_payload(dedupRoot),
]);
expect(searchLocalCacheIndex(dedupIndex, 'tax'), hasLength(1));
});
});
}