Skip to content

Reschedule due-card reminders on all mutation paths #175

@Pairadux

Description

@Pairadux

Problem

Due-card reminders are currently rescheduled only on:

  • App launch (via `notificationBootstrapProvider`)
  • Study session end (two call sites in `StudySessionScreen`)
  • Notification settings change

Other mutations that affect due dates are not covered:

  • Deleting a due card — notification may fire for a day with no remaining due cards
  • Sync pull — new due dates may arrive (or existing ones may be removed) from another device
  • Bulk operations (future) — move/delete affecting due dates

Desired behavior

At each mutation point, ensure the scheduled notification set matches the actual distinct due dates. No full wipe-and-reschedule — instead, diff the currently-scheduled IDs against the fresh due-date set and only cancel/add the delta.

Since notification IDs are date-based (`YYYYMMDD`), we only care about which days have at least one due card — no count recalculation needed. This keeps the cost proportional to the number of changed days, not the total number of scheduled notifications.

Approach (suggestion)

  1. Add an incremental `syncSchedule()` method to `DueReminderScheduler` that:
    • Queries `getDistinctDueDates()`
    • Loads the currently-persisted scheduled IDs
    • Computes the diff (IDs to cancel, IDs to add)
    • Only touches the delta
  2. Call `syncSchedule()` (not `rescheduleAll()`) from:
    • Card delete (single + future bulk)
    • Sync pull completion
  3. Keep `rescheduleAll()` for app launch and settings changes where a full rebuild is appropriate.

Performance constraint

This must not add perceptible latency to card mutations. The `getDistinctDueDates()` query is already indexed and lightweight, but it should still be fire-and-forget (`unawaited`) at call sites where the user is waiting on a UI transition.

Metadata

Metadata

Assignees

No one assigned

    Labels

    cardsFlashcard creation, editing, and managementenhancementNew feature or requestperformancePerformance optimization

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions