perf: async cache reads in content repository

This commit is contained in:
2026-06-12 13:24:14 +09:00
parent e722fe2ce1
commit 73a56aeeb1
+7 -6
View File
@@ -26,12 +26,12 @@ class ContentRepository {
return SeasonPack.fromJson(jsonDecode(raw) as Map<String, dynamic>);
}
SeasonPack? _loadCachedSeason(Directory dir) {
Future<SeasonPack?> _loadCachedSeason(Directory dir) async {
try {
final file = File('${dir.path}/pack.json');
if (!file.existsSync()) return null;
if (!await file.exists()) return null;
return SeasonPack.fromJson(
jsonDecode(file.readAsStringSync()) as Map<String, dynamic>);
jsonDecode(await file.readAsString()) as Map<String, dynamic>);
} catch (_) {
return null; // Corrupt or future-schema pack: ignore.
}
@@ -51,9 +51,10 @@ class ContentRepository {
final seasonsDir =
cacheDir == null ? null : Directory('${cacheDir!.path}/seasons');
if (seasonsDir != null && seasonsDir.existsSync()) {
for (final entry in seasonsDir.listSync().whereType<Directory>()) {
final pack = _loadCachedSeason(entry);
if (seasonsDir != null && await seasonsDir.exists()) {
await for (final entry in seasonsDir.list()) {
if (entry is! Directory) continue;
final pack = await _loadCachedSeason(entry);
if (pack != null) byId[pack.seasonId] = pack;
}
}