1

My situation is as follows: I have a collection in Mongo which gets updated with new items every few milliseconds, for example log items. I'm displaying these items on the frontend via publish/subscribe in a template, but because of the high volume the list updates so frequently that it's hard to read them. What I would like is to only have the list be updated every (few) seconds. I have tried to use sleep/timeouts on both the client and server side, as indicated here for example, without success so far.

  • Can I still use publish/subscribe for this or should I switch a polling mechanism with Meteor.setInterval?
  • Should the time interval part be on the publish or on the subscribe side?
  • If publish/subscribe is correct for my scenario, how do I only show the updated data every few seconds?
Community
  • 1
  • 1
Freek
  • 179
  • 1
  • 5
  • 13
  • have you tried with collection observers? appending your list as documents get added to the collection? it shouldn't reupdate your whole list. – Mathieu K. Jan 08 '17 at 09:39

2 Answers2

1

DDP has a rate limiter. it's meant for defeating DDoS attacks, but i suppose it could be repurposed for what you want.

https://blog.meteor.com/rate-limiting-in-meteor-core-762b8ad2412f#.nw6fwlhji

zim
  • 2,386
  • 2
  • 14
  • 13
-1

You should be able to use reactive variables and autorun in your Template.name.onCreated to do this :

Template.name.onCreated(function(){
var instance = this;
instance.now = new ReactiveVar( new Date());
instance.autorun(function(){
   var test = now.get();
   instance.subscribe('yourSubNameHere');
   setTimeout(function(){ //will update now and fire the autorun again
      instance.now.set(new Date());
   },timeoutHere)
});
)};

Although if your collection gets big I'd advise doing this with a limit in your publication maybe?

Mathieu K.
  • 903
  • 8
  • 27
  • i don't understand how this works. doesn't this just keep re-subscribing? – zim Jan 05 '17 at 16:36
  • are your documents being added on the client or server side? – Mathieu K. Jan 06 '17 at 09:13
  • i don't understand how re-subscribing solves the OP's problem. if i understand correctly, his data is coming too fast on the first subscribe. so i'm trying to understand how subsequent re-subscribes help. – zim Jan 06 '17 at 13:15
  • no worries! i kept asking because i wanted to find out if there was some hidden feature of subscribing i needed to be aware of. – zim Jan 06 '17 at 15:35