I'm curious about how the stale=update_after
feature of the CouchDB view API works.
I can see here that it returns stale results and then updates the view:
If stale=ok is set, CouchDB will not refresh the view even if it is stale, the benefit is a an improved query latency. If stale=update_after is set, CouchDB will update the view after the stale result is returned. update_after was added in version 1.1.0.
Assume that I have inserted some large number of documents -- enough to require several minutes to update the view index -- and then I query the view twice in rapid succession with stale=update_after
. The first query will return very quickly; that's the whole point of update_after
.
My question is, will the 2nd query also return stale results quickly, or will it wait for the view to finish updating?
The default value for many OSes is 1024 or 4096. On a system with many databases or many views, CouchDB can very rapidly hit this limit.
Basically views are JavaScript codes which will be put in a document inside the database that they operate on. This special document is called Design document in CouchDB. Each Design document can implement multiple view. Please consult Official CouchDB Design Documents to learn more about how to write view.
The second query also returns stale results. It uses the partial results that are available at the time the query hits the server. If you just added documents, you're fine.
But if you have modified your view, the first query will return the results of the first query and trigger a complete rebuild of the view. So the second query will probably deliver no results or just very few rows.
So the short answer: In your case, both queries will return quickly, with the second query probably giving the same result as the first one, maybe with some additional rows.
Hope I could help!
Yours, Bernhard
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With