0

We are using meteor V1.5 in our project. We noticed a strange behavior with publish and subscriber method. Posting a screen shot from KADIRA for one of the subscriber enter image description here

publish method

Meteor.publish( 'companyBuiltCourses', companyId => {  
    return BuiltCourses.find({ company_id: companyId })
});

When we use below subscriber and we visit xyz page, KADIRA shows continuous fetching of documents as shown in screen shot. Even though we visit another page, this graph remains same

Template.xyz.onCreated(function() {
   Tracker.autorun( () => {
     if (Meteor.user()) {
        Meteor.subscribe('companyBuiltCourses',Meteor.user().profile.company_id);
     }
   });
});

When we use below subscriber method and we visit xyz page, KADIRA shows continuous fetching of documents as shown in screen shot. But when we visit another page, this graph goes down to 0. It won't fetch document anymore

Template.xyz.onCreated(function() {
   this.autorun( () => {
     let self = this;
      if(Meteor.user()){
        self.subscribe('companyBuiltCourses',Meteor.user().profile.company_id);
     }
   });
});

For development environment both methods fetch documents only once when required. This is the PRODUCTION issue.

We are hosting MongoDB remotely and we run production on pm2. There should not be a continuous fetching I guess.

  • How large is your BuiltCourses collection? If it takes a long time to fetch data from server to client using publish/subscribe pattern, you should consider changing it to a server method. – Sudheer Jami May 17 at 1:17
  • Thanks for comment. No, It's not taking time to get data. I am only worrying about this continuous graph. It shoudn't be – Jimish Gamit May 17 at 8:52
0

It's pretty hard to tell what is going on, as the code you provide is simple enough. The only thing I can think of, is that the tracker function is being called repeatedly. So the question is, what causes that?

This code: Meteor.user().profile.company_id suggests that you are storing data against the user's profile in the user collection. This isn't great, because the user can modify their own data from the console, and also the accounts system modifies the user record at times, which may affect how many times subscriptions fire. I would recommend storing the related data in a separate collection anyway, which can be keyed by Meteor.userId(). I'm not sure if that's the answer to this one.

  • Thanks Mikkel for pointing out security loop hole. My main concern is about that continuous graph. I am agree with you that tracker function is being called repeatedly somehow. – Jimish Gamit May 17 at 8:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.