From 73a56aeeb1b92cafb1ace631cec9752fed37d593 Mon Sep 17 00:00:00 2001 From: airkjw Date: Fri, 12 Jun 2026 13:24:14 +0900 Subject: [PATCH] perf: async cache reads in content repository --- lib/data/content_repository.dart | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/data/content_repository.dart b/lib/data/content_repository.dart index c86d206..76e2848 100644 --- a/lib/data/content_repository.dart +++ b/lib/data/content_repository.dart @@ -26,12 +26,12 @@ class ContentRepository { return SeasonPack.fromJson(jsonDecode(raw) as Map); } - SeasonPack? _loadCachedSeason(Directory dir) { + Future _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); + jsonDecode(await file.readAsString()) as Map); } 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()) { - 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; } }