Skip to content

Batch selected-day preparation prefetch to avoid serial N+1 calls #531

Description

@jjoonleo

Problem

The calendar selected-day preparation prefetch loads preparation durations one schedule at a time. For a selected day with N uncached schedules, the app performs N sequential preparation requests before the duration map is fully populated. This can make busy calendar days feel slow and creates avoidable API chatter.

Evidence

  • MonthlySchedulesBloc requests preparation prefetch for the visible date after schedule loads and visible-date changes.
  • The prefetch handler filters missing schedule IDs, then loops through them serially with await inside the loop.
  • Each loop iteration calls LoadPreparationByScheduleIdUseCase, which delegates to PreparationRepository.getPreparationByScheduleId(scheduleId).
  • PreparationRepositoryImpl.getPreparationByScheduleId performs a remote fetch per schedule ID and publishes the result to the preparation stream.
  • The remote data source maps each schedule ID to one HTTP GET via /schedules/{scheduleId}/preparations.

Proposed direction

Add a bulk preparation-loading path for selected-day schedules. Preferred: expose a backend/API batch endpoint that accepts multiple schedule IDs and returns preparation durations or preparation steps keyed by schedule ID, then add repository/use-case support that updates the existing preparation stream/cache in one operation.

If backend batching is not immediately available, reduce frontend latency by fetching missing IDs concurrently with per-ID error isolation, preserving the current behavior where failed preparation loads are ignored and fallback UI remains available.

Acceptance criteria

  • Selecting a day with multiple uncached schedules no longer performs serial per-schedule preparation loading.
  • The selected-day prefetch path issues either one batch request or concurrent bounded requests instead of awaiting each schedule ID in sequence.
  • Existing cache behavior is preserved: already-loaded schedule preparation durations are not refetched.
  • Partial failures still do not fail the whole calendar day; successful preparation durations are shown and failed ones keep fallback UI.
  • Tests cover multi-schedule selected-day prefetch, cached IDs, and partial failure behavior.

Source: Codex codebase audit on 2026-06-28.

Metadata

Metadata

Assignees

No one assigned

    Labels

    codex-readyCan be started independently by a Codex thread nowenhancementNew feature or requestpreparationrelated to preparation featurepriority: P2Medium priority production-readiness workschedulerelated to schedule feature

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions