⚡ Optimize exercise data fetching with shared context#44
⚡ Optimize exercise data fetching with shared context#44
Conversation
…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>
|
👋 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. |
|
I have implemented a performance optimization for exercise data fetching. By introducing an
ExerciseProviderandExerciseContext, 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 theuseExerciseshook (such as theExerciseSelectormodal) 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