feat(flutter): extend metadata prefetch to library tabs + artist detail

MetadataPrefetcher gains warmAlbums(ids) / warmArtists(ids) public
methods so callers can fan out drift-cache warm-ups for whatever
collection just landed.

Wired into:
- Library Artists tab — warms first 8 artists from the page on every
  data emit (initial + paginate + refresh).
- Library Albums tab — same for first 8 albums.
- Artist detail album grid — warms first 8 albums from the artist's
  album list as soon as it loads, so tapping into any of them is a
  drift hit.

Hard-cap of 8 per call (same as the home prefetch). Set spans across
calls aren't deduped at this layer because providers themselves
short-circuit on cached values.

Also instrument the artist-detail play button: try/catch around the
artistTracksProvider read + playTracks call, snackbar on
empty-tracks or thrown-error so silent failures stop being silent.
The current behavior was an early return on tracks.isEmpty with no
visible feedback.
This commit is contained in:
2026-05-11 18:52:37 -04:00
parent 22152b1ba3
commit 4bd069430b
3 changed files with 78 additions and 15 deletions
+26 -5
View File
@@ -5,11 +5,9 @@ import '../library/library_providers.dart';
import '../models/home_data.dart';
/// Pre-warms the drift cache for entities the user is most likely to
/// tap. When /api/home returns its sections, fire one albumProvider /
/// artistProvider read per top-of-section item in the background. The
/// reads trigger the existing cold-cache path, which writes drift.
/// By the time the user actually taps a tile, it's a drift hit and
/// the detail screen renders instantly.
/// tap. The home prefetch fires when /api/home returns. Library
/// tabs and artist detail expose `warmAlbums` / `warmArtists` so they
/// can fan out reads from their own AsyncNotifier callbacks.
///
/// All reads are unawaited and idempotent — providers that already
/// have a cached value short-circuit. Readers/writers don't conflict
@@ -28,6 +26,29 @@ class MetadataPrefetcher {
/// the user can see without scrolling on a typical phone.
static const _topN = 8;
/// Pre-warm drift for each album id (no-op past the first dedup).
/// Called from the library Albums tab + artist detail album grid.
void warmAlbums(Iterable<String> ids) {
var n = 0;
for (final id in ids) {
if (id.isEmpty) continue;
if (n++ >= _topN) break;
_swallow(_ref.read(albumProvider(id).future));
}
if (n > 0) debugPrint('metadataPrefetcher: warming $n albums');
}
/// Pre-warm drift for each artist id.
void warmArtists(Iterable<String> ids) {
var n = 0;
for (final id in ids) {
if (id.isEmpty) continue;
if (n++ >= _topN) break;
_swallow(_ref.read(artistProvider(id).future));
}
if (n > 0) debugPrint('metadataPrefetcher: warming $n artists');
}
void _warmHome(HomeData h) {
final albumIds = <String>{};
final artistIds = <String>{};