meteorhacks / unblock

this.unblock inside publications :D
MIT License
87 stars 14 forks source link

Subscriptions accumulate when rerun #13

Open jacobparis opened 8 years ago

jacobparis commented 8 years ago

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 8 years ago

Having the same problem. Any update?

jacobparis commented 8 years ago

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 https://github.com/meteorhacks/unblock/issues/13#issuecomment-247821948, or mute the thread https://github.com/notifications/unsubscribe-auth/AFX2qL0llKPqlOZYQk0hL1Mk7a6AkHAOks5qrKsjgaJpZM4Ij2vs .

jindrichbartek commented 7 years ago

It's not bug. It's feature. Btw. explanation: https://github.com/meteorhacks/unblock/issues/11#issuecomment-266263478