-
Notifications
You must be signed in to change notification settings - Fork 45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
just wondering how well does this package play along with publish-composite #43
Comments
As I understand it... I'm not surprised by the odd behavior. publish-counts docs don't speak much about the hazards of having multiple counts. Primarily, you must ensure every subscription uses a unique name for the count, otherwise subscriptions will overwrite the same count, leading to errors. Or another way to put it, never subscribe to the same count twice (there are exceptions). It should be possible to use publish-counts and publish-composite together. I expect it will be very redundant. This example is rushed and untested, so there may be some errors. if (Meteor.isServer) {
Meteor.publishComposite('topTenPosts', {
find: function () {
var cursor = Posts.find({}, { sort: { score: -1 }, limit: 10 });
// counter will always be ten *shrug*
Counts.publish(this, 'topTenPostsCount', cursor, { noReady: true });
return cursor;
},
children: [
{
find: function (post) {
// find post author
return Meteor.users.find(
{ _id: post.authorId },
{ limit: 1, fields: { profile: 1 } });
}
},
{
find: function (post) {
// find comments on post
var cursor = Comments.find(
{ postId: post._id },
{ sort: { score: -1 } });
Counts.publish(
this,
'commentCountForPost' + post._id, // the id is necessary to ensure
// publish-counts saves the number
// of comments for each post as a
// separate document in the Counts
// Collection.
Comments.find({postId: post._id}),
{ noReady: true });
return cursor;
}
},
]
});
}
if (Meteor.isClient) {
var sub = Meteor.subscribe('topTenPosts', function () {
console.log('top ten posts count', Counts.get('topTenPostsCount'));
Posts.find({}).fetch().forEach(function (post) {
console.log('comment count for post', post._id, ':', Counts.get('commentCountForPost' + post._id));
});
});
} Don't underestimate the necessity to publish counts with unique names. Each time In the example above, the count If this answers your question, feel free to close the issue. Otherwise I'll leave it open for others to comment. |
Recently updated the Readme and found that when returning cursors, |
This does not work for me. As soon as I add the Counts() call to the parent's |
If you were using the same cursor for |
Thanks, wasn't aware of #58! |
I tried publishing some counts in a nested publication function and I'm getting some odd behavior. Anyway, it's just a general question
The text was updated successfully, but these errors were encountered: