Search code examples
firebasevue.jslocal-storagegoogle-cloud-firestorevuex

Checking for New Entries in Firestore - Local Storage


So I have a Firestore database where i have all my posts in, I push them on page load into the store so I can have a fast navigation and only need to fetch once.

What I wanna do now is to use a persisted state so i dont need to refetch it if the user opens a new window or F5(reloads) the page.

The problem is im not sure how to check if new Posts are in the Firestore without querying all posts and I havent found any methods to do it in a healthy and Read efficient way.


Solution

  • There's no super easy way around it - at the end you have some data, and the server has another, you need to check for differences.

    If you're only trying to figure out if there are new posts on the backend, which are not loaded on your frontend, then just get the date on your last post, and then ask Firebase for all posts after this date :)

    Of course if you don't have posts, ask for everything.

    Keep in mind you need to manually check if posts are deleted ;)