Performance on rules
I want to implement rules on my project with convex-ents but I am concerned about the performance impact this will have.
In my schema I have a chat and a message table.
To protect my messages I want to make sure that the message can only be read if the user that wants to access the message is in a chat that the message lives in.
But then if I load a chat with this:
Will every message checked if the message is in the chat?
If yes that would make the rules feature unusable for me.
5 Replies
I think this problem looks very similar to this from GraphQL:

N+1 is mostly about dependent fetches from the app where the latency can be 80ms+ or 150ms+ or whatever back to the database. if I'm understanding your situation here, your dependent fetches are just within the database itself -- effectively JOINs. the latencies for dependent operations here are like 0-2ms. So it's nothing to worry about
Will every message checked if the message is in the chat?Yes. When using RLS there's a fundamental trade-off between DevX (the rules are in one place and always executed) and performance (sometimes executing the rule is expensive especially when lists are involved). This is why I actually didn't use RLS in saas-starter and I haven't really found a need yet for using RLS (a team of developers working together might make the trade-off play out differently). On the flip side, doesn't each message belong to only one chat? In that case the rule execution should be pretty cheap, especially if Convex correctly caches the 1 privateChat read (which I'm not sure right now Convex does unfortunately).
So it would be cheaper to execute the authorise check not on the rules level but on the query level?
Correct.