I’ve got a particularly absurd publication that sets off warning bells in my head.
Just how bad is it to have 3.5 levels of nested children in a single publication?
What alternatives are there?
Is it time to bite the bullet and use grapher or Apollo? (I’d rather not have to refactor the entire data layer)
I would guess the main potential issue here would be performance? If that’s the case, it would make sense to try it out with some real world data before making any big changes. If the number of documents being returned is not very large, then perhaps just rolling with it is the best option.
It doesn’t look too bad to me, especially as the queries aren’t too complex, and some query by _id, which is the most efficient way to use Meteor’s pub/sub. If you want to optimize, I could suggest:
switching to methods, and using pub/sub where real-time is needed
filter out unnecessary fields
set limits if necessary
If you’re worried about publishComposite, or have real performance issues because of it, I suppose it would not be too hard to manage individual subscriptions using Tracker.
Since being reactive is only a nice-to-have, I’m going to switch it to a method and publish a reactive flag to notify the client if content updates are available (and a flag to force the client to fetch new data).
That should give a nice balance between the two without massive memory usage
Why not using mongo aggregate and lookups? aggregate/lookup is more efficient since it does the join at the DB (I think Grapher is making use of it) instead of fetching everyting and joining at the server.
The benefit of grapher for me is that I can easily swap reactive (publication with publish-composite) and non-reactive (method) queries.
The reactive queries have another extra: When I have a list of items and I create/delete/edit one of them, I get the updated list “for free”, meaning I don’t have to deal with refetchQuery. If I use non-reactive queries I have to either refetch everything after every change or write a bunch of helper functions to update my “local cache”.