Skip to content

fix: RTK cache & load interval improvements #196

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Conversation

peppidesu
Copy link
Contributor

@peppidesu peppidesu commented Feb 14, 2025

Fixes #198.

  • No longer using pollingInterval to update activities in real-time, as this is useless; The property is used to refetch while component is mounted, but activities unmounts before the first refetch even happens.
  • Every api now has keepUnusedDataFor: 60 * 60. This is to keep the cache alive even when no components that need it are currently mounted.
  • Added setupListeners call to main.tsx to allow RTK query to respond to events like disconnect/reconnect
  • Added refetchOnReconnect: true to every api to force refetch immediately after getting online again.
  • Added refetchOnMountOrArgChange to every api to refetch data on mount after VITE_LOAD_INTERVAL seconds have passed, which is how we achieve polling rate.

This means that currently, all APIs will only execute a request when:

  • A component mounts and at least VITE_LOAD_INTERVAL seconds have passed since the last fetch.
  • The internet connection is restored

And will return cached data otherwise (if available)

@peppidesu peppidesu requested review from stickyPiston and removed request for stickyPiston February 14, 2025 23:03
@peppidesu peppidesu marked this pull request as draft February 15, 2025 11:40
@KoenDR06
Copy link
Contributor

I know this PR is in draft mode, but it looks good to me! When this PR is ready for review, feel free to request a review from me

@peppidesu
Copy link
Contributor Author

Bad news:

image

RTK Query invalidates the cache upon sending the request, which means we cannot solve this problem with RTK Query alone, and we will have to create a custom cache layer.

@peppidesu peppidesu changed the title fix: recovery after disconnect fix: RTK cache & polling interval improvments Feb 25, 2025
@peppidesu peppidesu changed the title fix: RTK cache & polling interval improvments fix: RTK cache & load interval improvments Feb 25, 2025
@peppidesu peppidesu marked this pull request as ready for review February 25, 2025 19:06
@peppidesu peppidesu requested review from stickyPiston and KoenDR06 and removed request for stickyPiston February 25, 2025 19:07
@KoenDR06
Copy link
Contributor

Doesn't the bad news you outlined in your previous comment block this PR?

@KoenDR06 KoenDR06 changed the title fix: RTK cache & load interval improvments fix: RTK cache & load interval improvements Feb 28, 2025
@KoenDR06
Copy link
Contributor

@peppidesu

Could you respond? I genuinely don't know if this PR is ready to be merged or not now.

@peppidesu
Copy link
Contributor Author

Hi, sorry for getting back to you so late.

No, the PR is not blocked, as it now solves a different problem than was initially intended.

@KoenDR06
Copy link
Contributor

#198 doesn't seem to be fixed for me on this branch.

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.

Weather doesn't update after the initial load
2 participants