meteorhacks/unblock

Subscriptions accumulate when rerun

jacobparis opened this issue · 3 comments

In a normal setting, I can set up a simple autorun loop and reactively update a subscription, for example to increase a limit.

Meteor.autorun(function () {
  var limit = Session.get('postLimit'); //Default at 5

  Meteor.subscribe('threads', limit);
});

and with a regular publication this works great. If I change postLimit to 6, one additional post will appear increasing the total posts on screen to 6.

However if I unblock the publication, it is now executing asynchronously which causes the subscriptions to pile up every time I change the limit, leaving something that simulates

Meteor.subscribe('threads', 5);
Meteor.subscribe('threads', 6);
Meteor.subscribe('threads', 7);

Which on its own wouldn't be the worst thing in the world, but the results are not merged. The above example would occur if I were to set the postLimit (which starts at 5) to 6, and then to 7. Instead of displaying 7 posts, it displays 18, like so.

A
B
C
D
E
A
B
C
D
E
F
A
B
C
D
E
F
G

A similar effect was documented in the blog post I'll link to below. He ran into this problem using lodash debounce.
http://blog.east5th.co/2015/01/19/the-dangers-of-debouncing-meteor-subscriptions/

brg8 commented

Having the same problem. Any update?

I forget exactly why I figured it was happening, but I stopped unblocking
the publication to avoid the problem. I think it detached the content from
the subscription handler.

On Sep 17, 2016 9:09 PM, "brg8" notifications@github.com wrote:

Having the same problem. Any update?


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#13 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AFX2qL0llKPqlOZYQk0hL1Mk7a6AkHAOks5qrKsjgaJpZM4Ij2vs
.

It's not bug. It's feature. Btw. explanation: #11 (comment)