feat(flutter): drift-first History tab
Slice 4 of the smooth-loading pass. Adds CachedHistorySnapshot (schema 4) and rewires _historyProvider through cacheFirst, mirroring the homeProvider pattern: yield the last cached page immediately on subscribe so the tab paints from disk on cold open, then SWR-refresh in the background to surface fresh plays. Also enables basic offline scrollback — the most recent History page survives both app restart and connectivity loss. JSON blob storage (vs columnar) because the page is small, always read whole, and HistoryPage.fromJson already accepts the wire shape, so server-side field additions don't force a migration. History delta sync via library_changes is out of scope here; the next visit's SWR pull is the source of freshness for now.
This commit is contained in:
Vendored
+22
-1
@@ -128,6 +128,20 @@ class CachedHomeSnapshot extends Table {
|
||||
Set<Column> get primaryKey => {id};
|
||||
}
|
||||
|
||||
/// Single-row cache of the /api/me/history response. Mirrors the
|
||||
/// CachedHomeSnapshot pattern: opening the History tab in the Library
|
||||
/// screen yields the last-known page immediately while a fresh REST
|
||||
/// pull lands underneath via SWR. Also makes basic offline scrollback
|
||||
/// possible — the last fetched page survives both app restart and
|
||||
/// loss of connectivity. Schema 4+.
|
||||
class CachedHistorySnapshot extends Table {
|
||||
IntColumn get id => integer().withDefault(const Constant(1))();
|
||||
TextColumn get json => text()();
|
||||
DateTimeColumn get updatedAt => dateTime().withDefault(currentDateAndTime)();
|
||||
@override
|
||||
Set<Column> get primaryKey => {id};
|
||||
}
|
||||
|
||||
enum CacheSource { manual, autoLiked, autoPlaylist, autoPrefetch, incidental }
|
||||
|
||||
@DriftDatabase(tables: [
|
||||
@@ -140,12 +154,13 @@ enum CacheSource { manual, autoLiked, autoPlaylist, autoPrefetch, incidental }
|
||||
AudioCacheIndex,
|
||||
SyncMetadata,
|
||||
CachedHomeSnapshot,
|
||||
CachedHistorySnapshot,
|
||||
])
|
||||
class AppDb extends _$AppDb {
|
||||
AppDb([QueryExecutor? e]) : super(e ?? driftDatabase(name: 'minstrel_cache'));
|
||||
|
||||
@override
|
||||
int get schemaVersion => 3;
|
||||
int get schemaVersion => 4;
|
||||
|
||||
@override
|
||||
MigrationStrategy get migration => MigrationStrategy(
|
||||
@@ -167,6 +182,12 @@ class AppDb extends _$AppDb {
|
||||
// empty; the first /api/home fetch populates it.
|
||||
await m.createTable(cachedHomeSnapshot);
|
||||
}
|
||||
if (from < 4) {
|
||||
// Schema 4: cached_history_snapshot for drift-first
|
||||
// History tab. Same pattern as cached_home_snapshot —
|
||||
// empty on upgrade; first /api/me/history fetch populates.
|
||||
await m.createTable(cachedHistorySnapshot);
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user