Updating a CBLView

14 views
Skip to first unread message

Brendan Duddridge

unread,
Jul 14, 2015, 5:47:15 AM7/14/15
to mobile-c...@googlegroups.com
If I want to update a CBLView, is it better to adjust the map block's version number or just delete and re-create the view? The view will be user generated based on parameters, so I'm thinking it's just easier to delete the view and re-create it. Just want to know which is better and/or more efficient. I just didn't want to have to manage the version numbers of the views.

Jens Alfke

unread,
Jul 14, 2015, 12:07:31 PM7/14/15
to mobile-c...@googlegroups.com

On Jul 14, 2015, at 2:47 AM, Brendan Duddridge <bren...@gmail.com> wrote:

If I want to update a CBLView, is it better to adjust the map block's version number or just delete and re-create the view? The view will be user generated based on parameters, so I'm thinking it's just easier to delete the view and re-create it.

It’s slightly less efficient to re-create the view, because it involves dropping and re-creating SQLite tables (or ForestDB key/value stores.) But I don’t think the difference is noticeable.

You might consider doing what the CBLQueryBuilder does: it takes the parameters that affect the map function and generates a unique digest from them (by putting them in an NSDictionary, converting to canonical JSON, then taking the SHA-1 of the JSON data.) You can use that digest as the view’s version string. The advantage of this is that it’ll automatically invalidate the index if the parameters change, without your having to keep track of what the old parameter values were.

—Jens

Brendan Duddridge

unread,
Jul 14, 2015, 1:41:44 PM7/14/15
to mobile-c...@googlegroups.com
That's a great idea Jens!

Thanks!

Brendan
Reply all
Reply to author
Forward
0 new messages