tags:

views:

120

answers:

1

I've seen it mentioned in a couple of places that it takes a while to generate a view the first time it's referenced in couchDB, but I haven't found any sort of estimate of how long it should take. More specifically, I'm trying to test a view I created and it takes so long to load that I cannot tell if I screwed up the view, or if I'm just too impatient to let the view finish generating. The map function for the view is pretty simple:

function(doc){
  emit(doc.name, null);
}

I know that all the documents have a name field because I did some validation before importing them, and there is no reduce function. There are about 11,000 documents in the database, and I basically want to sort them by name.

I navigated to the view's page in futon last night and let it work for about 30 minutes without seeing any results. It seems pretty strange that it should take even that long, since a result shows up relatively quickly when the above function is used for a temporary view. Should it take this long to generate a view in CouchDB? If not, what could lead to a situation like this?

+1  A: 

It turns out there was no problem with the map function, but the culprit was actually the reduce function. I created the view using couchapp, and the default reduce function was the following:

function(key, values, rereduce){

}

Notice that it doesn't actually return anything. Without a return value, CouchDB was apparently running the map/reduce cycle over and over again, and never actually stopping. Removing the reduce function from the view fixed the problem.

And to answer the original question, it did not take very long to generate the view. On my computer it took ~20 seconds.

TwentyMiles
jchris just committed a change to use json2.js instead of json.js in the default view server. This means that if you use newer version of spidermonkey with the optimized C JSON parser it'll be used and view generation should at least double, probably triple depending on your document size.
mikeal