percolatestudio / publish-counts

Meteor package to help you publish the count of a cursor, in real time
https://atmospherejs.com/tmeasday/publish-counts
MIT License
200 stars 46 forks source link

Excessive warnings when using accessor function without query field specifier #57

Closed boxofrox closed 9 years ago

boxofrox commented 9 years ago

From #53

@tmeasday @boxofrox

Only one a bit annoying issue with this is that i constantly get warnings in the console:

W20150807-13:23:45.353(2)? (STDERR) publish-counts: unused fields removed from cursor fields option. { _groupId: 0 }

Is there any chance to move that to some debug block which can be enabled be developer if needed?

boxofrox commented 9 years ago

Without a field specifier, the accessor function causes publish-count to fetch entire documents, instead of only those fields necessary to maintain a proper count. The field specifier is recommended.

@kristijanhusak I take it the second solution from earlier didn't work with the field specifier [1]? If it does, then you won't receive the warnings.

I'm more inclined to have the debug option be opt-out rather than opt-in in development. Or if I can detect a production environment, disable the warning automatically. I'll take a look.

boxofrox commented 9 years ago

Notes to self.

kristijanhusak commented 9 years ago

@boxofrox I tested that first solution again, it is working, but now i get both warnings

W20150812-11:59:15.770(2)? (STDERR) publish-counts: unused fields detected in cursor fields option { _groupId: 1, day: 1, user: 1 }
W20150812-11:59:15.775(2)? (STDERR) publish-counts: unused fields removed from cursor fields option. { _groupId: 0 }

I need to specify more fields because of the query, not just _groupId. Here's the code:


Meteor.publish('calculateTasksTime', function(from, to, user) {
  var tasks = Tasks.find({
    time: {$gt: 0},
    day: {
      $gte: moment(from).startOf('day').unix(),
      $lte: moment(to).endOf('day').unix()
    },
    user: user
  }, {
    fields: { _groupId: 1, time: 1, day: 1, user: 1}
  });

  Counts.publish(this, 'calculateTasksTime', tasks, {
    countFromField: 'time'
  });
});

Hope this is helpful to you.
boxofrox commented 9 years ago

@kristijanhusak wierd.

I think those two warnings are from separate Counts.publish calls, otherwise the second warning would remove day and user also.

The first warning is expected for the code you provided, and I'm glad to hear that it works.