How to query messages only from a user’s friends (~1000 friends/user, ~100k messages/topic).
Simplified schema:
What I expected to do is the equivalent of SQL:
But Convex filters don’t support an “in” operator for a large dynamic array.
What my options seem to be:
Huge OR chain:
This is not reasonable for ~1000 IDs?
Or: Fetch all recent messages by index and filter in JS:
This only works if I pick an arbitrary recent window. It does not solve searching through all 100k messages without scanning everything.
My question:
What is the recommended Convex approach for:
“Get all messages in channel X where authorId is in a large dynamic list (1000 items)”
without scanning the entire channel and without generating a massive OR chain?
I get that I can denormalize this and have a view for each user, where the messages that get written are duplicated per user to make it O(1) at read time. But this could be 1000x more writes per message which doesn't make sense to do.
