Initiate collection reload/API call based on a Database notification indicating changes have happened since previous load

Hello!
I might be going from A to B through K below, please share any pointers!

With Supabase in the backend:

  • I have a backend filtering API call/Supabase plugin call that fetches a specific collection.
  • I don’t want it to be Dynamic and make the call again every time it loads so I save an “instance” of the search results object in a variable.

(same effect as manually activating a “Cached” collection reload from database. Correct?)

Issue: I need a way to determine when I need to initiate the refresh of the collection
I only need to do this in the case something in the data inside has changed in the database.

Can I have the database send a call to my app and “flick a switch” that says : there are pending changes so before you use this collection again make sure to reload.

I know the fields In which I expect changes to happen and should be monitored in the database.

The database needs to know when the data was last loaded for this to work(?)
I think the simpler: just “flick the switch” whenever something happens so we know, would also work?

Thank you!

You can do this with realtime, but you’d need to use a little but of JS.

1 Like

Doesn’t realtime have the risk of hitting rate limits? Apart from calling cost and browser load this is the third reason I am looking at this. Does realtime or something else cover all three?

It really depends on the usecase, but I don’t think rate limits and Supabase might be an issue. I’d need to know the whole workflow to be able to advice you more in depth. But I think this could be doable, what you’re describing is websockets, which is basically realtime. If you feel like you might need some extra help cracking this, I also do 1:1 sessions where we discuss these kind of tough problems in a more in depth and tailored way.

1 Like

Thank you @Broberto !