LiveQuery is not refreshed when some properties other than key are changed


#1

I have a view and a live query like this

var tagsView = database.viewNamed("tags")
tagsView.setMapBlock({ (doc, emit) in
    let type = doc["type"] as! String
    if type == "tag" {
        let order = doc["order"] as! Int
        emit(order, nil)
    }
}, version: "1")
var tagsQuery = tagsView.createQuery().asLiveQuery()
tagsQuery.addObserver(self, forKeyPath: "rows", options: [], context: nil)
tagsQuery.start()

And when I update ‘order’ property, ‘observeValueForKeyPath’ is called.
But when I update other property, for example ‘tag’, ‘observeValueForKeyPath’ is not called.

Is this a feature? or a bug?

If this is a feature, is there a way to force refresh?
‘CBLLiveQuery.queryOptionsChanged’ seems not helpful.


#2

LiveQuery only posts a notification when the results of the query change. If you update a document property that doesn’t affect the behavior of the map function, it doesn’t change the view index at all, so the query won’t notify you.

If you’re using a LiveQuery to drive a UI, you should emit the properties of the documents that you’re displaying in the UI. This is more efficient (you can get the values directly out of the QueryRow instead of having to load the whole document) and it also causes the view index to change when those properties change, so you’ll be notified.