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

Incompatibility with tmeasday:publish-counts? #12

Open
hluz opened this issue Aug 13, 2015 · 2 comments
Open

Incompatibility with tmeasday:publish-counts? #12

hluz opened this issue Aug 13, 2015 · 2 comments

Comments

@hluz
Copy link

hluz commented Aug 13, 2015

When using subs-cache to manage a subscription that has a Counts.publish, after a subscription is stopped - sub.stop() - and then re-started (re-subscribing again), the published counts stop being pushed to the client via DDP... If it is not stopped and just re-subscribed (for example if it is subscribed within a autorun in a Template onCreate callback due to change on criteria), all works fine.

Any idea?

@ccorcos
Copy link
Owner

ccorcos commented Aug 13, 2015

Hmm. this is only on the client so I'm not sure why this is happening...

@hluz
Copy link
Author

hluz commented Aug 14, 2015

Yes, true, its clients-side only. But consider:

In a pub set up like:

Meteor.publish('items', function(search,limit) {
  // checks, etc. here
  Counts.publish(this, 'items-count', Items.find(search), { noReady: true });
  return Items.find(search, {limit: limit, sort: {createdDate: -1}})
});

this is to be used in a list template, of course, where different search criteria and limit(n) can be specified by the user, an we can show only the first n items but also showing how many items were found. e.g, with {{getPublishedCount 'posts'}}

This works fine because every time there is a subscription call, a new items-count will be pushed to the client. For this scenario to work with subs-cache, of course the subsCache must be defined with cacheLimit: 1. My intent to use subs-cache here is, by having cacheLimit: 1, expireAfter: 5 is to allow the user go go away from the list screen and if returning within 5 minutes not to have to re-subscribe again if the criteria hasn't changed.

What I think it is happening:

Sometimes/under some weird condition, when leaving the list screen with criteria-A and then returning to the list screen with criteria-B, subs-cache is subscribing again without enforcing the cacheLimit of 1, keeping the first sub (criteria-A) in cache. In if the user goes away again from the list screen and then back with criteria-B, the first sub is matched as being cached and is not re-subscribed. In this case, although the find from mini-mongo may restrict the results to criteria-A, the publishedCount does not get updated and still shows the value for criteria-B (this is exactly the symptom I see).

I have tried to look in the cache on the console and indeed I managed to see a few times two cached subs for a subsCache that should have a limit of 1.

Apologies for not being able to follow your code... I love coffee but only of the liquid type. :-(

Thanks for your time

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

2 participants