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

SubsManager does not return object with the same API as Meteor.subscribe? (missing stop method) #15

Open
Sewdn opened this issue Jul 23, 2014 · 13 comments

Comments

@Sewdn
Copy link

Sewdn commented Jul 23, 2014

I can't use the stop() method on subscriptions returned by the SubsManager, whereas I can stop them manually when returned by Meteor.subscribe.

Use case:
I subscribe to a Stats publication for all documents that are clientside available (and don't have an internal cached stats object):

Events.find({stats: {$exists: false}}).observe({
      added: function(doc){
        var sub = subsMngr.subscribe("eventStats", doc._id);
        //var sub = Meteor.subscribe("eventStats", doc._id);
        statsSubscriptions[doc._id] = sub;
      },
      removed: function(doc){
        statsSubscriptions[doc._id].stop();
        delete statsSubscriptions[doc._id];
      }
    });

When an event is not clientside available anymore, the stats shouldn't be published anymore and the stats-subscription must be stopped.

I want to cache these subscription, because events happen to be published and unpublished quite a log in my app, and the stats are quite expensive.

This doesn't seem to be possible, because I can't stop the statsSubscription?!
Does this mean, I can just never stop the subscription and they will stop automatically?

It seemed to me the cache would only become stale, when a subscription was stopped (AND cachetime expired)? No?

@arunoda
Copy link
Contributor

arunoda commented Jul 23, 2014

Yes. This is a current limitation.
We need to tweak a bit to support this.


Arunoda Susiripala
I curate Meteor Weekly - Check it out!
http://meteorhacks.com/meteor-weekly/?utm_source=email-footer&utm_medium=email&utm_campaign=meteorweekly

On Wed, Jul 23, 2014 at 3:39 PM, Pieter Soudan [email protected]
wrote:

I can't use the stop() method on subscriptions returned by the
SubsManager, whereas I can stop them manually when returned by
Meteor.subscribe.

Use case:
I subscribe to a Stats publication for all documents that are clientside
available (and don't have an internal cached stats object):

Events.find({stats: {$exists: false}}).observe({
added: function(doc){
var sub = subsMngr.subscribe("eventStats", doc._id);
//var sub = Meteor.subscribe("eventStats", doc._id);
statsSubscriptions[doc._id] = sub;
},
removed: function(doc){
statsSubscriptions[doc._id].stop();
delete statsSubscriptions[doc._id];
}
});

When an event is not clientside available anymore, the stats shouldn't be
published anymore and the stats-subscription must be stopped.

I want to cache these subscription, because events happen to be published
and unpublished quite a log in my app, and the stats are quite expensive.

This doesn't seem to be possible, because I can't stop the
statsSubscription?!
Does this mean, I can just never stop the subscription and they will stop
automatically?

It seemed to me the cache would only become stale, when a subscription was
stopped (AND cachetime expired)? No?


Reply to this email directly or view it on GitHub
#15.

@Sewdn Sewdn changed the title SubsManager does not object with the same API as Meteor.subscribe? (missing stop method) SubsManager does not return object with the same API as Meteor.subscribe? (missing stop method) Jul 23, 2014
@bryanterrell
Copy link

Hey Sewdn,

Thought I'd post this since I had the same issue - I needed to clear the cached subscriptions when a user logged out. I ended up using a work around of re-initializing the SubsManager like this:

cacheManager = new SubsManager({ cacheLimit: 0, expireIn: 0 });

@arunoda
Copy link
Contributor

arunoda commented Feb 4, 2015

@bryanterrell you need an API to remove all subscriptions. That could be done easily. So, you need an API like cacheManager.clear().

@bryanterrell
Copy link

Yeah, that would be perfect. Thanks

@bryanterrell
Copy link

FYI, my workaround does appear to clear the subs, but the collection I subscribed to still shows data so this didn't work even after updating the cached sub and doing a reset.

@arunoda
Copy link
Contributor

arunoda commented Feb 6, 2015

@bryanterrell I've added an .clear() api.
see: https://github.com/meteorhacks/subs-manager#clear-subscriptions

@bryanterrell
Copy link

@arunoda It seems to be working - thanks for addressing this so promptly!

@arunoda
Copy link
Contributor

arunoda commented Feb 6, 2015

great.

On Sat Feb 07 2015 at 4:21:30 AM Bryan Terrell [email protected]
wrote:

@arunoda https://github.com/arunoda It seems to be working - thanks for
addressing this so promptly!


Reply to this email directly or view it on GitHub
#15 (comment)
.

@apendua
Copy link

apendua commented Aug 29, 2015

@arunoda What's the status of this ticket?

@apendua
Copy link

apendua commented Aug 29, 2015

To my understanding the problem is that we cannot really stop a subscription until we are sure nobody needs it, so we need to track the number of subscriptions with the same parameters, right?

@arunoda
Copy link
Contributor

arunoda commented Sep 9, 2015

I think giving a ability to remove a single subscription seems not perfect for the use of this. But it's technically possible.

I'm thinking to merge FlowRouter's subscriptions management functionality to this as well. With that, I hope we can do something.

@thebarty
Copy link

+1 for finding a solution for this

@adammoisa
Copy link

@arunoda having trouble with .reset() - when I run it, it removes all docs from client. Seems like it doesn't re-subscribe.

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

6 participants