Checking if we have the up to date document _rev #2996
-
What is the simplest way to verify if the revision of a document that we currently hold is the latest one in Couch? Background: |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
Yo can use the same mechanism interacting with CouchDB. Use HEAD operation for a document HEAD /db/doc If you have the same revision than the one is the current winning revision, it will respond 304 Not Modified You'll find the same behaviour with the GET /db/doc operation |
Beta Was this translation helpful? Give feedback.
-
This is answered already, but it got me thinking: which is faster: reading out a doc, and discarding the body before returning it (HEAD), or just looking up the doc metadata in I got myself various databases with varying doc sizes (see below), all databases have 1M docs, that are generated with benchbulk.sh. I used these contraptions to get the timing between the last byte sent to the server and first response byte in curl -v --trace-time`:
UPDATE: h/t @garrensmith, no measuring until the end of the request, to make it a fairer comparison, AND to account for hate act that CouchDB will send the view result metadata before doing the actual lookup: 1 byte docs: HEAD: 1100-1600 microseconds, _all_docs: 1300-1700 microseconds The stock I stopped after this ;) In conclusion: there is one more way to do this, if you don’t need the Note that this is a rather speed SSD system here (recent Mac mini) and fast CPUs. I’m running the tests many times to avoid caching artefacts, but that means all access should be cached. So you’d likely see more differences on slower disk and for uncached requests.
|
Beta Was this translation helpful? Give feedback.
-
Awesome, thanks for the detailed info ;-) |
Beta Was this translation helpful? Give feedback.
Yo can use the same mechanism interacting with CouchDB. Use HEAD operation for a document
HEAD /db/doc
HEADER If-None-Match="<rev>"
If you have the same revision than the one is the current winning revision, it will respond 304 Not Modified
You'll find the same behaviour with the GET /db/doc operation