Firestore security rules - read count in a batch

Viewed 423

If in a batch I update documents A and B and the rule for A does a getAfter(B) and the rule for B does a getAfter(A), am I charged with 2 reads for these or not? As they are part of the batch anyway.

Example rules:

match /collA/{docAid} {
  allow update: if getAfter(/databases/$(database)/documents/collA/${docAid}/collB/{request.resource.data.lastdocBidupdated}).data.timestamp == request.time
    && ...
}

match /collA/{docAid}/collB/{docBid} {
  allow update: if getAfter(/databases/$(database)/documents/collA/${docAid}).data.timestamp == request.time
    && getAfter(/databases/$(database)/documents/collA/${docAid}).data.lastdocBidupdated == docBid
    && ...
}

So are these 2 reads, 1 per rule, or no reads at all?

2 Answers

firebaser here

I had to check with our team for this. The first feedback is that it doesn't count against the maximum number of calls you can make in a single security rule evaluation run.

So the thinking is that it likely also won't count against documents read, since it doesn't actually read the document. That said: I'm asking around a bit more to see if I can get this confirmed, so hold on tight.

Are you using two different documents?

If it is the case, then two reads will be performed.

Related