Skip to content

#213 - feat(feedback): Reduce Frontend API calls #339

Draft
eo2000 wants to merge 26 commits intodevfrom
213/reduce-api-calls
Draft

#213 - feat(feedback): Reduce Frontend API calls #339
eo2000 wants to merge 26 commits intodevfrom
213/reduce-api-calls

Conversation

@eo2000
Copy link
Copy Markdown
Collaborator

@eo2000 eo2000 commented Mar 31, 2025

Summary

This PR reduces frontend API calls by caching them using react-query.

Changes Made

  • Added react-query Integration
  • Optimized API calls in SettingsPanel and AvailableDatasets:
    - Implemented useQuery to fetch and cache data on component mount, optimizing API calls by setting a 5-minute staleTime and a 10-minute cacheTime.
    - Added useMutation to handle data updates and directly sync the cache using setQueryData, ensuring immediate UI updates and reducing unnecessary refetching.

Testing Instructions

  1. Open the app and wait for the initial getConfig request (in Network tab on inspect).
  2. Click the Settings button/Language Button (in Settings Panel) or Name/Date filters in Available Datasets 3-5 times within 5 minutes.
  3. Check the Network tab for getConfig requests—only one should occur on mount.

Video Demo

Setting Panel API calls before react-query

SettingsNoRQ.mov

Setting Panel API calls with react-query

SettingsWithRQ.mov

AvailableDatasets API calls before react-query

AvailDatasetsNoRQ.mov

AvailableDatasets API calls with react-query

AvailDatasetsRQ.mov

Additional Notes

I ran into some issues while implementing the react-query caching in the Footer and MapMetaData components. Since we aim to complete coding ASAP, I decided to leave those out for now. However, there are still opportunities for further optimizations to reduce API calls using react-query.

@eo2000 eo2000 marked this pull request as draft March 31, 2025 03:48
@eo2000 eo2000 changed the title #213 - [Feedback] Reduce Frontend API calls #213 - feat(feedback): Reduce Frontend API calls Apr 1, 2025
@eo2000
Copy link
Copy Markdown
Collaborator Author

eo2000 commented Apr 11, 2025

This is a draft pull request capturing work in progress during Release 3. It is not fully ready for merge, but is being documented here for transparency and potential future continuation.
As part of the capstone handoff, we are unassigning ourselves from this pull request.

Next steps for this PR:

  • Fix tests for AvailableDatasets
  • Use similar approach done in SettingsPanel and AvailableDatasets to reduce the API calls for the other frontend components

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