Skip to content

⚡ Optimize exercise data fetching with shared context#44

Open
Joacohbc wants to merge 1 commit intomasterfrom
performance-optimize-exercise-selector-fetches-12233200015560558256
Open

⚡ Optimize exercise data fetching with shared context#44
Joacohbc wants to merge 1 commit intomasterfrom
performance-optimize-exercise-selector-fetches-12233200015560558256

Conversation

@Joacohbc
Copy link
Copy Markdown
Owner

I have implemented a performance optimization for exercise data fetching. By introducing an ExerciseProvider and ExerciseContext, I've shifted the exercise state from a per-hook-instance model to a global shared model. This ensures that the database is only queried once during initial application load (or when explicitly refreshed), rather than every time a component using the useExercises hook (such as the ExerciseSelector modal) is mounted. This significantly reduces redundant I/O and improves the responsiveness of the application when navigating or opening modals.


PR created automatically by Jules for task 12233200015560558256 started by @Joacohbc

…edundant DB fetches

This change refactors the exercise data fetching logic from the `useExercises` hook into a global `ExerciseProvider` using React Context.

Key improvements:
- Moves exercise state and DB interaction logic to `src/contexts/ExerciseContext.tsx`.
- Refactors `useExercises` to consume the shared context, ensuring all components share a single source of truth.
- Eliminates redundant IndexedDB fetches when components like `ExerciseSelector` (modal) are repeatedly mounted and unmounted.
- Uses `useMemo` for the context value to prevent unnecessary re-renders of consumer components.
- Improves application-wide performance by centralizing data management and reducing I/O overhead.

The change is transparent to existing consumers of `useExercises` as the hook signature remains unchanged.

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
@google-labs-jules
Copy link
Copy Markdown
Contributor

👋 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 @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@github-actions
Copy link
Copy Markdown

PR Preview Action v1.8.1

🚀 View preview at
https://Joacohbc.github.io/routine-builder/pr-preview/pr-44/

Built to branch gh-pages at 2026-02-28 05:12 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant