Overlap when subscriptions with skip/limit and subscriptionsReady

I have found two different workarounds.

The first does not rely on Template.instance().subscriptionsReady() and instead uses a reactive var to trigger readiness

Template.gigaCollection.onCreated(function(){
 var self = this;
 var ready = new ReactiveVar(false);
 var skip = new ReactiveVar(0);
 var limit = 12;
 self.autorun(function(){
  self.ready.set(false);
  self.subscribe('gigaCollection', {sort:{name:1},skip: self.skip.get(), limit: self.limit},function(){
   self.ready.set(true);
  });
 })
});

this solution really tests for readiness :slight_smile:

The second hack has to do with making sure a Collection.find after a skip/limit shows only the new dataset. It is a bit more involved by adding a value to the result set that is uniq to the request. You can use a uniq id (Meteor.uuid) or a timestamp. I had success by simply adding the skip value.

Collection = new Meteor.Collection('something');
if(Meteor.isServer) {
 Meteor.publish('something', skip, limit, function(){
  var handler = Collection.find({},{skip: skip, limit: limit}).observeChanges({
     added: function(id, doc) {
      doc.skip = skip;
      self.added('something', id, doc);
     }
  });
  self.ready();
  self.onStop(function () {
   if(handler) handler.stop();
  });
 });
}
if(Meteor.isClient) {
 Template.something.onCreated(function(){
  var self = this;
  this.autorun(function(){
   self.subscribe('something', Session.get('skip'), 10);
  });
 });
 Template.sometemplate.helpers({
  something: function() {
   return Collection.find({skip: Session.get('skip')});
  }
 });
}

Let me know what you think