perf(inventory): lazy list, photo thumbnails, indexes, debounced reload

Scale the local inventory to 10k+ varieties:
- Render the list with ListView.builder over a flattened header/item model
  instead of building every tile upfront.
- Store a small regenerable JPEG thumbnail per photo (schema v14) and use it
  for the 48px list avatar; full bytes stay for offer image hosting. Existing
  photos are backfilled lazily at startup. Thumbnail is local-only (excluded
  from CRDT sync and backups by the JSON codec).
- Add indexes on varieties(is_deleted,is_draft), attachments(parent_type,
  parent_id,kind), lots(variety_id) via @TableIndex.
- Debounce watchInventoryView (~250ms) so a burst of table writes triggers one
  reload, not seven.
- cacheWidth/cacheHeight on the list avatar decode.
- Scale test raised 3k -> 10k; migration test v13 -> v14.
This commit is contained in:
vjrj 2026-07-20 17:48:37 +02:00
parent 2884ddd3c7
commit 3de01bd948
12 changed files with 5114 additions and 34 deletions

View file

@ -34,6 +34,26 @@ String? offerThumbnailDataUri(
}
}
/// Builds a small JPEG thumbnail (longest edge [edge]px) for the inventory-list
/// avatar, so the list never has to decode the full-resolution photo. Returns
/// raw JPEG bytes, or null on undecodable input (the caller falls back to the
/// full photo). Kept as local bytes regenerable, so it is excluded from sync
/// and backups.
Uint8List? inventoryThumbnailBytes(
Uint8List bytes, {
int edge = 96,
int quality = 72,
}) {
try {
final decoded = img.decodeImage(bytes);
if (decoded == null) return null;
final resized = _fitWithin(decoded, edge);
return Uint8List.fromList(img.encodeJpg(resized, quality: quality));
} catch (_) {
return null;
}
}
/// Extracts the raw bytes from a `data:...;base64,` URI, or null when [uri] is
/// not a base64 data URI. Used by the UI to render an inline thumbnail with
/// `Image.memory` instead of a network fetch.