perf(species): seed the bundled catalog only once per version

Skip the ~1.5 MB catalog parse and the table scan on every launch — the
main startup cost. `seedBundledIfNeeded` re-seeds only when the recorded
version differs from `speciesCatalogVersion`, writing the version after
the seed commits so an interrupted seed retries next launch.

Adds `parseSpeciesCatalogVersion` and a test keeping the constant in sync
with the asset's `version` field.
This commit is contained in:
vjrj 2026-07-10 15:46:04 +02:00
parent c9c764e624
commit ea5ab0342d
4 changed files with 87 additions and 0 deletions

View file

@ -31,3 +31,16 @@ Future<List<SpeciesSeed>> loadBundledSpecies() async {
final jsonString = await rootBundle.loadString(_catalogAsset);
return parseSpeciesCatalog(jsonString);
}
/// Version of the bundled catalog, mirrored from the asset's `version` field
/// (written by `tool/gen_species_catalog.dart`). A test asserts the two stay in
/// sync. The app records the version it last seeded and skips the ~1.5 MB parse
/// and the table scan in [SpeciesRepository.seedBundled] on every subsequent
/// launch so bumping this (alongside the asset) is what triggers a one-time
/// re-seed after the catalog changes.
const int speciesCatalogVersion = 3;
/// Reads just the `version` field from a catalog JSON string. Used by the sync
/// test to keep [speciesCatalogVersion] aligned with the asset.
int parseSpeciesCatalogVersion(String jsonString) =>
(jsonDecode(jsonString) as Map<String, dynamic>)['version'] as int;