1

I am trying to read from firebase to get real-time updates from the database.

    useEffect(() =>
        onSnapshot(collection(db, 'announcements'), async (snapshot) => {
            let oldData = announcementsData;
            let temp = snapshot.docs.map(doc => doc.data());
            // sort temp by id in descending order
            temp.sort((a, b) => {
                return b.id - a.id;
            }
            );
            // console.log(oldData.length !== temp.length && oldData.length !== 0, oldData.length, temp.length, announcementsData);

            if (oldData.length !== temp.length && oldData.length !== 0) {
                await schedulePushNotification(temp[0].title, temp[0].description);
            }
            setAnnouncementsData(temp);

        })
        , [announcementsData]);

This is how I am fetching data. What I think I am doing it gets a a snapshot of the db, I have been told this doesn't count as read. But it still did exceed the quota. Can anyone tell how to keep checking database for updates without exceeding the quota.

007 AZx
  • 155
  • 8
  • are you writing to the `announcements` collection in setAnnouncementsData? This will cause a loop of writes and reads. How often is the data updated? What is your quota limit? – Chris Jul 21 '22 at 00:01
  • setAnnouncementsData updates react state, doesn't make changes to the database. Quota limit is 50k reads – 007 AZx Jul 21 '22 at 13:51

0 Answers0