couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Matt Goodall <matt.good...@gmail.com>
Subject _changes resource
Date Mon, 06 Jul 2009 12:50:45 GMT
Hi,

Not sure if this is a user or dev message so posting to both.

I've started playing with the _changes resource to improve the
response time of some update processes that currently use
_all_docs_by_seq. cron is not exactly high resolution and a fast poll
is just not a nice thing to do.


== API ==

AFAICT, the _changes API supports four query params:

* since: non-inclusive seq num to start emitting changes from.
* continuous: boolean to enable "streaming" mode.
* heartbeat: period of inactivity (ms) after which a heartbeat newline
will be sent. continuous=true only.
* timeout: period of inactivity (ms) after which the end of the
document is sent and the connection closed. continuous=true only.

Did I find everything and are my descriptions correct? (I can feel a
wiki page coming on ;-))


== Response Document ==

The response looks something like this:

$ curl "http://localhost:5984/test/_changes"
{"results":[
{"seq":2,"id":"75a5d0495630527b4641199681e1abc3","changes":[{"rev":"2-1358922619"}]},
{"seq":5,"id":"3fb654a7094e7cfb4774030ed5c0aefb","changes":[{"rev":"2-4123934944"}]},
{"seq":16,"id":"399f99e0a89856d4627833d1cd11bf10","changes":[{"rev":"11-1674861745"}]}
],
"last_seq":16}

Under what circumstances would 'changes' contain more than one item?
(Note: I couldn't see anything testing multiple 'changes').

Would it make sense to rename 'results' to 'rows' for just a little
consistency with a view's response?

Is last_seq at all useful?


== Line Breaks ==

If each results item is sent with its ending newline (the "," is sent
with the next item) it would make clients much easier and correct to
write, i.e. buffer bytes until a newline is received, split the
buffer, process the row, repeat. You've still got to remove the ","
from all but the first line but it's in a predictable place. Actually,
I don't believe TCP provides any guarantees that bytes sent are
received in the same chunks so relying on anything other than the
newline is probably flawed.

It's a trivial change, patch attached.


== Deleted and Conflicts==

_all_docs_by_seq includes a 'deleted' flag and a list of 'conflicts'.
Should the _changes API to do the same?


Hope that all makes sense.


- Matt

Mime
View raw message