getLatestSnapshotMetadata method
SessionStore.getSnapshot by sessionId (the session's latest leaf)
without the state: the same resolution, the same null-if-none contract,
and a row with state null. The resolved sessionId is carried on the
returned row even for a row that stored it only under state.
Implementation
@override
Future<SessionSnapshot?> getLatestSnapshotMetadata(
String sessionId, {
Map<String, dynamic>? context,
}) async {
normalizeGetSnapshotOptions(sessionId: sessionId);
// Fast path via the pointer file (skipped when we must detect branching):
// resolve the leaf id and read its metadata directly. Honor the pointer
// only when the leaf still exists and belongs to this session; a stale or
// foreign pointer falls through to the scan below. A corrupt pointer target
// propagates, exactly as the full read's fast path (`_snapshotById` in
// `_latestSnapshotForSession`) does, so the two paths stay identical.
if (!rejectBranchingSessions) {
final pointer = await _readPointer(sessionId, context);
if (pointer != null) {
final meta = await getSnapshotMetadata(
pointer.currentSnapshotId,
context: context,
);
if (meta != null && snapshotSessionId(meta) == sessionId) {
return meta;
}
}
}
// Fallback: the full scan resolves the leaf (and rewrites the pointer);
// strip its state on the way out.
final snap = await getSnapshot(sessionId: sessionId, context: context);
return snap != null ? stripSnapshotState(snap) : null;
}