perf: optimize sleep session db storage calls#1466
Conversation
PR Validation ResultsChange Detection
✅ All checks passed. Thank you! |
There was a problem hiding this comment.
Code Review
This pull request optimizes the synchronization of health data by separating sleep sessions from other session types. On the mobile client, sleep sessions are now chunked into smaller batches (SESSION_CHUNK_SIZE = 50) to prevent timeouts, while exercise and workout sessions remain grouped by source to support the server's range-delete behavior. On the server side, sleep session processing is optimized by pre-fetching and sharing the user profile and timezone context across the batch, eliminating redundant database queries. The reviewer suggested memoizing the context promise instead of the resolved value in getSleepContext to prevent potential race conditions and duplicate queries if the batch processing is refactored to run concurrently in the future.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
b017d83 to
d37770c
Compare
[!TIP]
Description
What problem does this PR solve?
Syncing large amounts of data will timeout due to a lot of db calls.
How did you implement the solution?
Sync smaller batches for sleep sessions and optimize db calls for sleep sync functions.
Linked Issue: Closes #1263
How to Test
PR Type
Checklist
All PRs:
New features only:
Frontend changes (
SparkyFitnessFrontend/):pnpm run validateand it passes.en) translation file.Backend changes (
SparkyFitnessServer/):rls_policies.sqlfor any new user-specific tables.UI changes (components, screens, pages):
Mobile changes (
SparkyFitnessMobile/):Screenshots
Click to expand
Before
After
Notes for Reviewers