My challenge involves managing a list that is subscribed to the 'posts' publication with a specified limit.
Publication
Meteor.publish('posts', function(options) {
check(options, {
sort: Object,
limit: Number
});
var posts = Posts.find({}, options);
return posts;
});
Each item in the list contains sub items.
list.html
{{#each posts}}
{{> postItem}}
{{/each}}
For each individual postItem
, I want to calculate the number of comments it has.
To achieve this, the code would look something like this:
Template.postItem.helpers({
commentsCount: function () {
return Comments.find({postId: this._id }).count();
}
});
The issue arises when considering efficiency, as publishing all comments within the 'posts' publication may not be optimal.
I am looking for a solution where I can create a separate publication at the Template level for each postItem
to retrieve and display only the comment counts. I have explored using packages like tmeasday:publish-counts
but have not been able to implement them effectively in my case.