Fetching more comments for a single post in a list of posts

So I have a feed pretty much like a Facebook feed, displaying the 10 most recent posts and 3 most recent comments per post (I’m using reywood:publish-composite to publish the lot).

I’d like to fetch all comments for a single post when a user clicks on “Show all comments” for that post. One way to do this is to have another publication which takes and array of post IDs for which I fetch all the comments. However, wouldn’t that reload the comments for every post in the list every time I add a new ID?

Ideally I’d also like to put a limit on how many additional comment are fetched (i.e. “Show 10 previous comments”). The only way I can think of doing that is by storing a list of comment IDs inside each post and then subscribing to a list of comments using an array of comment IDs (adding the IDs of the 10 previous comments to the array when a user clicks “Show 10…”). But again, would that cause the entire subscription to be reloaded every time I add IDs?

Meteor doesn’t reload documents that have already been published.

Regarding the “limit on how many additional comment are fetched”, you might consider using the skip and limit parameters of Collection.find().

Thanks for the reply. I’m a bit confused, in the Discover Meteor book they have the following example:

Meteor.publish('topComments', function(topPostIds) {
  return Comments.find({postId: topPostIds});
});

This would be a problem from a performance standpoint, as the publication would need to get torn down and re-established each time the list of topPostIds changed.

That’s why I was under the impression that it would re-publish everything every time I change the array of IDs.

How would I use the skip and limit parameters in this context? Since the comments for all the posts are published by a single publication.