On demand Publish on Meteor? -


is there way publish updates collection on demand? (e.g. send updates every 5 seconds?)

i publishing leaderboard, shows the top 50 players (have points) in game. updates users' points happen frequently, leaderboard changes (every 1-5 seconds). every minute or so, server updates points ~100 user in foreach loop. problem publish methods start updating right away, before 100 elements have been updated. creates painful performance issue (publishing updates users multiple times)...

is there way hold publish until updates done? or way update published data every 5 seconds instead of immediately?

thanks help! :)

create custom publication , take control!

var pubshandlers = [];  meteor.publish('totalscore', function() {   this.added('someclientcollection', 'totalscoreid', {     totalscore : somegettotalscorefunction()   });   pubshandlers.push(this); //maaaaybe not cleanest thing do.   this.ready(); });  meteor.setinterval(function updatescores() {   var newtotalscore = somegettotalscorefunction()   pubshandlers.foreach(function(pubhandler) {     pubhandler.changed('someclientcollection', 'totalscoreid', {       totalscore : newtotalscore   }); }, 5000); //each 5 seconds, update 

so here's what's happening:

  1. publishing in custom way, adding document our publication,
  2. remembering publication handler further updates,
  3. at later time (here in interval), use remembered handlers update document.

the main benefit keep server in full control of publication , updates.
main drawback use of push(this). it's not bad looks damn hideous...


Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -