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

**URL:** <https://community.weweb.io/t/initiate-collection-reload-api-call-based-on-a-database-notification-indicating-changes-have-happened-since-previous-load/9454>\
**Category:** Tips and Hacks\
**Tags:** filter, supabase\
**Created:** [June 30, 2024, 7:01am UTC](https://community.weweb.io/t/initiate-collection-reload-api-call-based-on-a-database-notification-indicating-changes-have-happened-since-previous-load/9454 "2024-06-30T07:01:32Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![loukas](https://avatars.discourse-cdn.com/v4/letter/l/49beb7/32.png) [@loukas](https://community.weweb.io/u/loukas)\
**Post date:** [June 30, 2024, 7:01am UTC](https://community.weweb.io/t/initiate-collection-reload-api-call-based-on-a-database-notification-indicating-changes-have-happened-since-previous-load/9454/1 "2024-06-30T07:01:32Z")

</div>

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!**

---

<div class="post-metadata">

**Author:** ![Broberto](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/broberto/32/5918_2.png) [@Broberto](https://community.weweb.io/u/Broberto)\
**Post date:** [June 30, 2024, 7:21am UTC](https://community.weweb.io/t/initiate-collection-reload-api-call-based-on-a-database-notification-indicating-changes-have-happened-since-previous-load/9454/2 "2024-06-30T07:21:09Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![loukas](https://avatars.discourse-cdn.com/v4/letter/l/49beb7/32.png) [@loukas](https://community.weweb.io/u/loukas)\
**Post date:** [June 30, 2024, 7:33am UTC](https://community.weweb.io/t/initiate-collection-reload-api-call-based-on-a-database-notification-indicating-changes-have-happened-since-previous-load/9454/3 "2024-06-30T07:33:21Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Broberto](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/broberto/32/5918_2.png) [@Broberto](https://community.weweb.io/u/Broberto)\
**Post date:** [June 30, 2024, 7:41am UTC](https://community.weweb.io/t/initiate-collection-reload-api-call-based-on-a-database-notification-indicating-changes-have-happened-since-previous-load/9454/4 "2024-06-30T07:41:20Z")

</div>

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](https://broberto.sk/consult) in a more in depth and tailored way.

---

<div class="post-metadata">

**Author:** ![loukas](https://avatars.discourse-cdn.com/v4/letter/l/49beb7/32.png) [@loukas](https://community.weweb.io/u/loukas)\
**Post date:** [June 30, 2024, 7:55am UTC](https://community.weweb.io/t/initiate-collection-reload-api-call-based-on-a-database-notification-indicating-changes-have-happened-since-previous-load/9454/5 "2024-06-30T07:55:29Z")

</div>

Thank you @Broberto !
