Is there an easy way to fetch multiple collections across different pages? (using Supabase)

Hey there,

Sorry if I sound like a newbie, perhaps it’s something obvious.

Across different pages we have different sections which shows content from the users group.

That group is coming from supabase id and tables, we have content like, all users, all animals, all groups and so on.

Using the collection function and filters, I made all sorts of different collections, like total sum of users with x role, and animals in this group and users in another group and so on.

The problem is that, this content changes a lot, it can change live, it can change whilst the user changes their group.

I assume fetching every single collection, on every page change, would seriously slow things down especially as we scale.

Is there another way to do what I’m doing, or fetch conveniently?

Because at the moment, fetching automatically and preserving navigation on collection fetching doesn’t do the justice in our case, it doesn’t update the collections accordingly which I’m having issues with.

Any ideas?

I appreciate it!

few things,

  • use the fetch collections in parallel rather then just fetching.
  • fetching automatically will fetch on page load if the collection is used on the page in a rendered section so if its used somewhere but conditional rendering is off it wont fetch.
  • Preserve on navigation will maintain the same collection and wont refetch if you switch pages.
  • on each page load only what is relevant to that page.
  • if the change is made by the user on the front end update the collection rather then refetching.
  • if the change is made not on the front end you will need to use something like realtime to tell the collection to update or refetch
1 Like

thank you so much for this!

can you elaborate on the before last point? how do I update the collection without refetching it?

i assumed that refetching it also updates it, because we send new info to the collection for example, and then then refetch so it updates on the front end too.

Thank you once again!

use the update collection workflow.

Yes it does update it if you refetch the whole collection, but you only need to update what you have changed ie if you updated 1 row you don’t need to refetch a collection of 50 rows.

1 Like