I have this publication of mine:
Meteor.publish(null, function() {
if (!this.userId) return this.ready();
var myCrew = [];
var myCompanyId = Profiles.findOne({userId : this.userId}).companyId;
myCrew = Profiles.find({companyId : myCompanyId}, {fields : {userId : 1}}).map(function(p){return p.userId;});
myCrew = _.union(myCrew, _.flatten(Channels.find({createdByUser : this.userId}).map(function(c){return c.partyIds;})));
myCrew = _.union(myCrew, Channels.find({partyIds : this.userId}).map(function(c){return c.createdByUser;}));
myCrew = _.union(myCrew, Invitations.find({guestId : this.userId, accepted : {$ne : libInvitationStatus.declined}}).map(function(i){return i.hostId;}));
myCrew = _.union(myCrew, [this.userId]);
return Meteor.users.find({_id : {$in : myCrew}}, {fields: {_id: 1, username: 1, emails: 1, 'profile.avatarUrl': 1, status : 1}});
});
and in my app I’m using Meteor.users
extensively. In my case the visibility at the client of users collection should change when the composition of myCrew
array changes. It depends on others collection like Channels and Invitations.
My question is: apart from using some server side reactive publishing –always dangerous IMHO because not included in Meteor core packages– is there another way to force invalidation of users collection?
Any standard pattern I can use in this case?
Thanks