Skip to content

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 preferring local_* override properties over the master data if is_local_override is 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 5 minutes (standard walking transition fallback) or 0 minutes if the acts occur on the same stage.

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 bands table where is_local_override === true.
  • Deletes only non-overridden local schedule rows and imports new bands that do not conflict with local overrides.