Search code examples
flutterfirebasegoogle-cloud-firestorefirebase-security

Does firestore rules validate every time when listener added?


This is the question previously i asked Questions about firestore cache and reads charge

Basically it says if i add same listener like below twice, I only get charge as single listener for receiving data.

db.collection("testCollection").onSnapshot(function(doc) {}); 
db.collection("testCollection").onSnapshot(function(doc) {});

But if I using get in rules on that path

match /testCollection/{documentId} {
   allow list: get(/databases/$(database)/documents/users/$(request.auth.uid)).data.isAllowToReadTestCollection;
}

Will the rules validate twice? Will I get charged for that get in rules twice?


Solution

  • Same as in the linked answer - since the listeners get deduped on the client before reaching the server, there should also only be a single evaluation of the security rules.