Summary
When _historyManager is present in WorkoutProvider.finishWorkout(), HistoryManager.addSession() persists and caches the session in HistoryManager._sessions. However, WorkoutProvider._sessions also inserts the same session immediately after (line 602 of workout-logger/lib/services/workout_provider.dart). This dual-state ownership can cause the two collections to drift apart:
- Direct mutations to
WorkoutProvider._sessions that bypass HistoryManager will desync the two caches.
- While
evictSession/patchSession are called on delete/update to propagate changes, any other direct mutations to _sessions would miss the sync.
Suggested Fix
When _historyManager != null, remove the _sessions.insert(0, session) path in WorkoutProvider.finishWorkout() and rely solely on HistoryManager._sessions as the authoritative source of truth for persisted sessions. Ensure _clearDraft() still runs and that all delete/update paths continue to delegate to HistoryManager.
This aligns with the broader refactoring roadmap to split WorkoutProvider into smaller, focused managers (WorkoutManager, HistoryManager, RoutineManager).
References
Requested by @Devasy.
Summary
When
_historyManageris present inWorkoutProvider.finishWorkout(),HistoryManager.addSession()persists and caches the session inHistoryManager._sessions. However,WorkoutProvider._sessionsalso inserts the same session immediately after (line 602 ofworkout-logger/lib/services/workout_provider.dart). This dual-state ownership can cause the two collections to drift apart:WorkoutProvider._sessionsthat bypassHistoryManagerwill desync the two caches.evictSession/patchSessionare called on delete/update to propagate changes, any other direct mutations to_sessionswould miss the sync.Suggested Fix
When
_historyManager != null, remove the_sessions.insert(0, session)path inWorkoutProvider.finishWorkout()and rely solely onHistoryManager._sessionsas the authoritative source of truth for persisted sessions. Ensure_clearDraft()still runs and that all delete/update paths continue to delegate toHistoryManager.This aligns with the broader refactoring roadmap to split
WorkoutProviderinto smaller, focused managers (WorkoutManager,HistoryManager,RoutineManager).References
Requested by @Devasy.