Skip to content
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

Count not updating when find() selector changes #82

Closed
abecks opened this issue Mar 8, 2016 · 5 comments
Closed

Count not updating when find() selector changes #82

abecks opened this issue Mar 8, 2016 · 5 comments

Comments

@abecks
Copy link

abecks commented Mar 8, 2016

I have a publication that looks like this:

    Counts.publish(this, 'CompanyInfiniteCount', app.collections.Company.find(query), {noReady: true});

    return app.collections.Company.find(query, {
      limit: limit,
      sort: sort
    });

Designed to give me the total count of company records, and then returning a limited cursor for pagination.

When query changes (to filter the list), the result of Counts.get('CompanyInfiniteCount') is not changing from it's initial value.

I am trying to achieve the same thing as this example in the docs:

Meteor.publish('posts-with-count', function() {
  Counts.publish(this, 'posts', Posts.find(), { noReady: true });
  return Posts.find({}, { limit: 10 });
});

But with a changing document selector. Am I using Counts wrong?

@abecks abecks changed the title Count not updating when find query changes Count not updating when find selector changes Mar 8, 2016
@abecks abecks changed the title Count not updating when find selector changes Count not updating when find() selector changes Mar 8, 2016
@DominikGuzei
Copy link

Same for me, any solution?

@boxofrox
Copy link
Contributor

@abecks.

I assume your Meteor.publish callback takes a query argument unlike the given example from the docs. If so, then you might be running into multiple Counts.publish conflicting because they all have the same name, 'CompanyInfiniteCount'.

I don't recall if Meteor automatically stops an existing subscription if you subscribe again with different arguments. If not, then save the handle returned by Meteor.subscribe and call handle.stop() before running Meteor.subscribe with the new query/selector.

There may be some overlap with an issue described in #66 in this comment.

If you can generate a very basic Meteor app that demonstrates this problem and upload it to github with a link in a comment here, I'll fidget with it and come up with some better advice.

@abecks
Copy link
Author

abecks commented Mar 10, 2016

@boxofrox you are 100% correct. I actually ended up abandoning Counts and I'm now periodically polling a server method for the count as needed. Still a great package!

@abecks abecks closed this as completed Mar 10, 2016
@boxofrox
Copy link
Contributor

@abecks glad you found a solution.

@DominikGuzei if you're still seeking a solution for this issue, let's begin in a new issue.

@DominikGuzei
Copy link

Haha, found the same "solution" as @abecks – polling methods, since that's the only performant way to count large collections. The realtime aspect is much less important for us 😉

But btw. my solution to the problem discussed here was to separate the counter publication from another one. So the problem seemed to be related with using Counts.publish and then returning another record set like Meteor.users.find(…) in the publication

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants