The-Commit-Company / Raven

Simple, open source team messaging platform
https://thecommit.company/products/raven
GNU Affero General Public License v3.0
250 stars 87 forks source link

feat: cache data locally #901

Closed nikkothari22 closed 2 months ago

nikkothari22 commented 2 months ago

SWR provides a way to use a custom cache provider. We now store the API calls in local storage as soon as the user reloads the page/exits the tab.

Example below with each API call throttled by 1 second:

Without cache (approx 12 seconds): Export-1714739655557

With cache (near instant): Export-1714739814425

The API calls are still being made - but since the results are cached, we're able to show the UI instantly. We still need to cache the APIs on the backend though.

Next steps:

  1. Avoid network request waterfalls (currently fetching users > channels > members > messages). We can remove all Context and reduce number of re-renders - just use SWR hooks directly and load everything in parallel.
  2. Avoid layout shifts when loading - remove all spinners and replace with perfectly sized skeleton loaders/boxes.