Skip to content

Consolidate dual session state between WorkoutProvider and HistoryManager #44

Description

@coderabbitai

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.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions