Single observer for a document that can change many ways vs. Many observers for the document that all focus on a specific change


#1

Suppose I have a user document which can change in 3 ways. Suppose observeChanges is not an option.
Which option is more efficient? Three lean observers, or one bulky one?

Users.findOne() ...
... {
        username: "Bob",
        tags: ['batman','soccer','fish','electron'],
        rating: 2.71828
    }

Username can become a different string. Tags can becoming a larger or smaller array, or the values inside can change. Rating can become a new number.

//single bulky observer, will run and check if tags, rating changed even if only username changed.
Users.find().observe({
	changed: function(newDoc, oldDoc){
		//if username changed, do something
		//if tags changed do something
		//if rating changed, do something
	}
})

//three observers, each very lean.
Users.find({},{fields:{tags:1}}).observe({
	changed: (newDoc, oldDoc){
		//we know what do to, no checking.
	}
})
//and the other two, not gonna write them...

Comparing three different solutions for observeChanges "CRON" jobs
#2

In general in Meteor it’s better to use few observers than many, so your first solution seems to be the better one (with the drawback you self must figure out which fields has been changed). I strongly doubt that the second solution would be better than the first one, but possible equally good, depending on how Meteor works internally, which I don’t know.


#3

well, I forgot to mention, but in the second case it’s only three
observeChanges whereas in the first case we are using observe, not
observeChanges.