kadirahq/subs-manager

sub doesn't fully run with multiple cursors in pub

markshust opened this issue · 2 comments

I'm trying to publish multiple cursors like so:

Meteor.publish("item_to_sections_items", function() {
  if (! this.userId) return;

  const user = Meteor.users.findOne({_id: this.userId});
  let itemIds = [];

  const itemToSectionsCursor = item_to_section.find({
    company_id: user.company_id
  }, {
    sort: {rank: 1}
  });

  _.map(itemToSectionsCursor.fetch(), function(itemToSection) {
    itemIds.push(itemToSection.item_id);
  });

  const itemsCursor = item.find({_id: {$in: itemIds}});

  return [
    itemToSectionsCursor,
    itemsCursor
  ];
});

However, the publication doesn't re-rerun/update after an addition to itemToSectionsCursor.

update: itemToSectionsCursor updates, itemsCursor does not.

Okay. This is what's happening. It's not a bug. That's how this works.

With subsManager you are caching the subscription. So, when you are browsing through pages subscription won't reestablish. That's why collection data won't update.

Try to use something reactive joins or avoid _id lookup in item.find({_id: {$in: itemIds}}); (I know it's hard to do).
May be then, subsManager is not a good solution for this.

Thank you -- I found a good blog on what is going on here (https://www.discovermeteor.com/blog/reactive-joins-in-meteor/). I'll just stick to react joins on client for now, however I have an interesting use case and will probably change this in future.