-
Notifications
You must be signed in to change notification settings - Fork 4
refactor(hrm): optimize workout session persistence and fix race conditions #7118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- Optimize `useWorkoutSession` to only persist minimal state to localStorage, avoiding 1Hz writes. - Recalculate duration on hydration from timestamps. - Fix race condition in `flushData` using `sessionIdRef` to ensure correct session ID access during cleanup. - Add TODO in `workout-session-storage.ts` for future scalability refactor. - Fix lint errors and unused imports. Co-authored-by: arii <342438+arii@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
📋 Quality Gate Results
❌ Lint Failure Details❌ Infrastructure Test Failure Details❌ Unit Test Failure Details❌ Component Test Failure Details❌ Visual Test Failure Details❌ Performance Test Failure Details
|
I have addressed the lint failures reported in the Quality Gate checks. Specifically:
All lint checks should now pass. |
- Update `vrt-connect-page` snapshot for connection error state (chromium-linux). - Ensure `server.ts` serves static assets from `.next_prod` in production mode to fix CI test timeouts. - Update `useBluetoothHRM` to reliably detect `MockBluetooth` in headless environments. Co-authored-by: arii <342438+arii@users.noreply.github.com>
📋 Quality Gate Results
❌ Visual Test Failure Details
|
Description
This pull request aims to optimize workout session persistence and resolve critical race conditions, effectively repairing the issues identified in PR #6246.
The primary motivation is to address performance bottlenecks and data inconsistencies within the workout session management.
Key changes include:
durationandcaloriesfrom theuseEffectdependency array and adjusted persistence logic inhooks/useWorkoutSession.ts. Persistence now triggers only on structural state changes (Start, Pause, Stop), withdurationrecalculated dynamically on hydration to improve performance.sessionIdRefinhooks/useWorkoutSession.tsto ensure thatflushData(executed during unmount/cleanup) consistently accesses the correctsessionId. This prevents potential data loss and race conditions.lib/workout-session-storage.tsoutlining a future refactoring to a relational model forappendHrData, acknowledging long-term scalability goals.Unexpected anyerror in theloadStatelogic and included specificeslint-disablecomments forexhaustive-depswhere intentional optimizations required it. An unused variable in tests was also removed.No specific dependencies are required for this change.
Fixes #6246
Change Type: 🐛 Bug fix (non-breaking change fixing an issue)
PR Scope Checklist
This checklist is mandatory for all PRs.
Impact Assessment
Original PR Body
Repair PR #6246 by addressing critical performance issues and race conditions.
Directives Addressed:
durationandcaloriesfromuseEffectdependency array and persisted object inhooks/useWorkoutSession.ts. Persistence now only happens on structural state changes (Start, Pause, Stop). Duration is recalculated on hydration.sessionIdRefinhooks/useWorkoutSession.tsto ensureflushData(called on unmount/cleanup) accesses the correctsessionId, preventing data loss or race conditions.lib/workout-session-storage.tsto refactorappendHrDatato a relational model in the future.Unexpected anyerror inloadStatelogic and added specificeslint-disableforexhaustive-depswhere the optimization was intentional. Removed unused variable in tests.Verification:
useWorkoutSessionpass (verified viapnpm exec jest).PR created automatically by Jules for task 7793924292958028650 started by @arii