Appearance
Offline "Now & Next" Engine Implementation
This document details the IndexedDB schema updates, querying utilities, and conflict resolution protections introduced to compute real-time on-device festival logistics.
Key Deliverables
Implemented the specifications in 15-offline-now-next-engine.md:
1. IndexedDB Schema Updates
Modified db.ts to extend the Band (Act) entity definitions to support local overrides:
is_local_override: boolean flag representing if the user has overridden the schedule times or stages.local_start_time: override start time (string/epoch).local_end_time: override end time (string/epoch).local_stage_id: override stage ID.
Defined an type alias Act = Band to match references in downstream logistics.
2. "Now & Next" Query Engine
Created the utility at nowAndNext.ts providing:
getEffectiveActSchedule(act): Extracts the active start time, end time, and stage ID for any act, dynamically preferringlocal_*override properties over the master data ifis_local_overrideis true.getNowAndNext(currentTimestamp):- Filters local IndexedDB for selected/prioritized user acts (
priority > 0). - Iterates and returns the act currently playing (
Now) and the immediate next act scheduled to start (Next). - Computes travel transition times between stages, defaulting to
5minutes (standard walking transition fallback) or0minutes if the acts occur on the same stage.
- Filters local IndexedDB for selected/prioritized user acts (
3. Sync Conflict Resolution (Upsert Merge)
Refactored the synchronization logic in sync.ts:
- Modified
hydrateSchedule()to perform a differential merge during database synchronization. - Scans and preserves any rows in the local
bandstable whereis_local_override === true. - Deletes only non-overridden local schedule rows and imports new bands that do not conflict with local overrides.