I'm writing the security rules for my Firestore database, and I got to the point where I'm probably writing too many checks and the authorization automatically fails.
For example the rules for a specific path are
service cloud.firestore {
match /databases/{database}/documents {
match /pending/{userId} {
match /rate/{vendorId}/events/{eventId}/ratings/{rateId} {
allow write: if request.auth.uid == userId
&& exists(/databases/$(database)/documents/vendors/$(vendorId)) // The vendor must exist
&& exists(/databases/$(database)/documents/users/$(userId)/subscriptions/$(vendorId)) // The user must be subscribed to the vendor
&& exists(/databases/$(database)/documents/vendors/$(vendorId)/events/$(eventId)) // The event must exist
&& !exists(/databases/$(database)/documents/vendors/$(vendorId)/events/$(eventId)/ratings/$(userId)) // The user must not have already voted for the event
}
}
}
}
These rules apply when writing to /pending/{userId}/rate/{vendorId}/events/{eventId}/ratings/{rateId}
Removing one or a combination of rules makes everything work again. I read on the documentation about a limit of 10 developer-defined functions here, but exists and get are listed as service-defined and should not be counted. Even if they were, here I'm only using five.
Is there a more efficient way to check the same fields? How do I calculate how much a single line counts into reaching the 10 functions limit?
Thanks