Skip to content

fix: query invalidation for daily progress#831

Merged
CodeWithCJ merged 1 commit intoCodeWithCJ:mainfrom
Sim-sat:fix-energy
Mar 3, 2026
Merged

fix: query invalidation for daily progress#831
CodeWithCJ merged 1 commit intoCodeWithCJ:mainfrom
Sim-sat:fix-energy

Conversation

@Sim-sat
Copy link
Contributor

@Sim-sat Sim-sat commented Mar 3, 2026

Description

There were some problems of data not refreshing after update. I found some issues with overlapping query keys and fixed all that I could find. Some keys and methods were not needed anymore and could be removed. I removed the invalidation based on the date since date formats are not equal in the whole app and instead invalidated all.

Related Issue

PR type [ ] Issue [ ] New Feature [ ] Documentation
Linked Issue: #

Checklist

Please check all that apply:

  • [MANDATORY for new feature] Alignment: I have raised a GitHub issue and it was reviewed/approved by maintainers
  • Tests: I have included automated tests for my changes.
  • [MANDATORY for UI changes] Screenshots: I have attached "Before" vs "After" screenshots below.
  • [MANDATORY for Frontend changes] Quality: I have run pnpm run validate (especially for Frontend).
  • Translations: I have only updated the English (en) translation file (if applicable).
  • Architecture: My code follows the existing architecture standards.
  • Database Security: I have updated rls_policies.sql for any new user-specific tables.
  • [MANDATORY - ALL] Integrity & License: I certify this is my own work, free of malicious code(phishing, malware, etc.) and I agree to the License terms.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request resolves data freshness issues within the application, particularly affecting daily progress views. The solution involves a comprehensive refactoring of query keys to eliminate overlaps and enhance precision. Additionally, the approach to data invalidation has been revised to use a broader, more reliable strategy, moving away from date-specific invalidations that were prone to errors due to varying date formats. This ensures that user interfaces consistently display up-to-date information after data modifications.

Highlights

  • Query Key Refactoring: Refactored and updated various query keys across admin, check-in, diary, exercise, meal, and settings modules for improved specificity and consistency, addressing issues with overlapping keys.
  • Daily Progress Service Consolidation: Removed the dedicated dailyProgressService.ts file, consolidating its data fetching functions directly into their respective services or refactoring their usage within hooks.
  • Enhanced Query Invalidation Strategy: Implemented a broader query invalidation approach for daily progress data by invalidating dailyProgressKeys.all on relevant mutations. This change moves away from problematic date-specific invalidation due to inconsistent date formats, ensuring data refreshes reliably.
  • User ID Integration in Mutations: Modified several mutations related to custom categories, profile updates, and avatar uploads to explicitly pass the userId, improving data scoping and consistency.
Changelog
  • SparkyFitnessFrontend/src/api/Diary/dailyProgressService.ts
    • Removed the dailyProgressService file, consolidating its functionalities.
  • SparkyFitnessFrontend/src/api/keys/admin.ts
    • Added a new avatar key to userKeys for managing user avatar queries.
  • SparkyFitnessFrontend/src/api/keys/checkin.ts
    • Introduced a rawStressData key to checkInKeys for specific data retrieval.
  • SparkyFitnessFrontend/src/api/keys/diary.ts
    • Removed goals and exercises keys from dailyProgressKeys.
    • Added a foodIntake key to foodEntryKeys.
  • SparkyFitnessFrontend/src/api/keys/exercises.ts
    • Added a dailyStats key to exerciseEntryKeys for daily exercise statistics.
  • SparkyFitnessFrontend/src/api/keys/meals.ts
    • Refactored mealPlanKeys to use a new all key and a byUser key for user-specific meal plans.
  • SparkyFitnessFrontend/src/api/keys/settings.ts
    • Removed the customCategoryKeys and profileKeys as they are no longer needed or have been relocated.
  • SparkyFitnessFrontend/src/hooks/CheckIn/useCheckIn.ts
    • Imported dailyProgressKeys for broader invalidation.
    • Added dailyProgressKeys.all invalidation to useDeleteCustomMeasurementMutation, useUpdateCheckInMeasurementFieldMutation, and useSaveCheckInMeasurementsMutation.
  • SparkyFitnessFrontend/src/hooks/Diary/useDailyProgress.ts
    • Removed imports from the deprecated dailyProgressService.
    • Updated data fetching for daily food intake, exercise stats, and steps to use direct service calls and refined query keys.
    • Removed the useDailyGoals hook from this file.
    • Updated useCalculatedBMR to use userKeys.profile.
  • SparkyFitnessFrontend/src/hooks/Diary/useFoodEntries.ts
    • Imported dailyProgressKeys.
    • Expanded query invalidation in food entry mutations (create, update, delete, copy) to include dailyProgressKeys.all and other relevant keys.
  • SparkyFitnessFrontend/src/hooks/Exercises/useExerciseEntries.ts
    • Modified exercise entry mutations (create, delete, log preset, delete preset) to invalidate dailyProgressKeys.all and exerciseEntryKeys.all.
  • SparkyFitnessFrontend/src/hooks/Foods/useMealplanTemplate.ts
    • Updated mealPlanKeys usage in useMealPlanTemplates, useCreateMealPlanMutation, useUpdateMealPlanMutation, and useDeleteMealPlanMutation to align with the new key structure.
  • SparkyFitnessFrontend/src/hooks/Reports/useReports.ts
    • Updated the queryKey for useRawStressData to use the new checkInKeys.rawStressData.
  • SparkyFitnessFrontend/src/hooks/Settings/useCustomCategories.ts
    • Changed imports from customCategoryKeys to checkInKeys.
    • Updated queryKey for useCustomCategories and passed userId to useAddCategoryMutation, useUpdateCategoryMutation, and useDeleteCategoryMutation.
  • SparkyFitnessFrontend/src/hooks/Settings/useProfile.ts
    • Changed imports from profileKeys to userKeys.
    • Updated queryKey for useAvatarQuery, useProfileQuery, useUpdateProfileMutation, and useUploadAvatarMutation to use userKeys.avatar and userKeys.profile.
    • Passed userId to useUpdateProfileMutation and useUploadAvatarMutation.
  • SparkyFitnessFrontend/src/hooks/useInvalidateKeys.ts
    • Imported goalKeys.
    • Added goalKeys.all and dailyProgressKeys.all to the useDiaryInvalidation hook for comprehensive invalidation.
  • SparkyFitnessFrontend/src/pages/Diary/DailyProgress.tsx
    • Removed the import of useDailyGoals from hooks/Diary/useDailyProgress.
    • Imported useDailyGoals from hooks/Goals/useGoals.
  • SparkyFitnessFrontend/src/pages/Settings/CustomCategoryManager.tsx
    • Passed user.activeUserId to useAddCategoryMutation, useUpdateCategoryMutation, and useDeleteCategoryMutation.
  • SparkyFitnessFrontend/src/pages/Settings/ProfileInformation.tsx
    • Passed user.activeUserId to useUploadAvatarMutation.
Activity
  • Sim-sat initiated this pull request to resolve data refreshing issues within the application.
  • The author identified that overlapping query keys and inconsistent date formats were causing data not to refresh correctly.
  • Unnecessary query keys and methods were removed to streamline the codebase.
  • The invalidation strategy was updated to invalidate all daily progress data, moving away from date-specific invalidation due to format inconsistencies.
  • The author has confirmed that pnpm run validate was run and that the code adheres to existing architectural standards and license terms.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request addresses issues with query invalidation by refactoring query keys and broadening invalidation scopes. The changes are logical and aim to improve data consistency. I've identified a potential bug where a query key is missing a dependency, which could lead to stale data, and also a minor code duplication in one of the hooks. Overall, a good set of changes to improve the robustness of data fetching.

@CodeWithCJ CodeWithCJ merged commit e4f2fe0 into CodeWithCJ:main Mar 3, 2026
6 checks passed
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.

2 participants