Hey guys and girls, hope you are all doing great. ...
# community-help
d
Hey guys and girls, hope you are all doing great. Got a bit desperate so here I am :)) Anyone use Search Firestore with Typesense extension and know how to "listen" for a collection update in Typesense and refetch data as soon as that happens? E.g. creating or deleting a document and updating the collection in real time, something like how Firestore's snapshot works? It of course works with a setTimeout delay and manually refetching, but surely that's not the way to do it.. Thank you!
j
@DomijKu The Typesense Firestore extension does this for you, but it does it in reverse - it watches your Firestore collection for any updates and then ingests the changes into Typesense in real-time: https://firebase.google.com/products/extensions/typesense-firestore-typesense-search
d
Thank you, Jason! Yes, I am aware of that. What I am trying to do is get some kind of trigger when that happens, so I could trigger an update on the front end. It does whenver the page rerenders of course, but I am trying to figure whether it can be real time. Does that make any sense?
j
Typesense doesn't have these triggers built-in. But you could create these triggers via a cloud function trigger on your Firestore database directly and use a pub-sub mechanism to broadcast the change to clients (See CaptainCodeman's note below)
d
Aaah, got it. That's a bit over my head for now, but at least I know where to start looking. Thank you very much, you are a legend! :)
👍 1
😄 1
c
You can just subscribe to firestore directly on the client, and it will trigger callbacks as the backend data changes
🙏 1
l
@DomijKu Typesense is a « replica » of your firestore and, through the extension, is updated anytime you CRUD your data in firestore. For real-time in your UI, you should get a stream subscription from firestore. If you have to get results from Typesense (for technical or price reasons for example), you could trigger a call to Typesense with a periodic timer but it is a little hacky
d
Thank you @Loïc. Excuse of naivete as I am quite a newbie, but do I understand correctly that I should use Firestore's onSnapshot for the regular use and switch to Typesense's collection whenever a search or sort happens?
👍 1
l
@DomijKu I recommend to switch on Typesense search as soon as you will go through more than 20 documents with Firestore
d
Thank you @Loïc!