Ruben Romero
ย ยทย Graphic designer addicted to FlutterFlow and complex logic

โŒ How to stop listeners on queries when the app is in the background and restart them when it's in the foreground?

Database & APIs

I'm not sure if anyone else has noticed the "rules metrics" section in Firestore. Everyone seems to be more concerned about the reads, updates, and delete counts, but the "allows" in the rules metrics section are much more important, as they also count as reads and grow faster than the reads.

My problem is that even when the app is in the background, or no new document reads are being generated because the query has already finished, the "allows" in the Firestore metrics continue to grow endlessly. This may be related to the query to "authenticated user" that is always available, as even on a page with no query, I can see that one read is executed, and the "allows" of the rules continue to rise endlessly. I was able to find the code to detect when the app is in the background, which is relatively simple, but I can't find any way to stop the listeners to Firestore when it's in the background. I even tried cutting off the internet connection, but the "allows" still keep growing. I need to stop these reads since in just one hour they reach around 300-500, even though I'm building the app alone (a simple app so far, with very few documents, around 5 reads on each page). With a few users, it would quickly surpass the 50,000 reads limit, making Firebase/FlutterFlow a very unprofitable option for real projects

What have you tried so far?

I have used cache to store the queries, I have tried on new pages with only one query, and even on pages that have no queries at all, the "allows" in the "rules metrics" of Firestore keep growing endlessly even though the app is in the background. I suspect it has to do with the "authenticated user" part of FlutterFlow. We need a way to stop the listeners of the Firestore queries

Did you check FlutterFlow's Documentation for this topic?
Yes
2
9 replies