On Aug 6, 2009, at 10:17 AM, Brian Candler wrote:

Raising a minor point here for discussion, rather than on JIRA.

With feed=continuous, the newline after the last record isn't sent until the
*next* record is available. For example:

$ telnet localhost 5984
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
GET /test/_changes?feed=continuous HTTP/1.0
Host: localhost

HTTP/1.0 200 OK
Server: CouchDB/0.10.0a (Erlang OTP/R12B)
Date: Thu, 06 Aug 2009 14:11:26 GMT
Content-Type: text/plain;charset=utf-8
Cache-Control: must-revalidate

{"results":[
{"seq":1,"id":"1f9bcccaadf2c3e9508d42532838595f","changes": [{"rev":"1-23202479633c2b380f79507a776743d5"}]}, {"seq":2,"id":"291e49cc084d2e180f3a5d313d255889","changes": [{"rev":"1-3975759ccff3842adf690a5c10caee42"}]}, {"seq":3,"id":"a6bdc0e451df85169178f0d9619b605a","changes": [{"rev":"1-027467bd0efec85f21c822a8eb537073"}]}
                --------------------->
                 stops at end of line

When the next record is generated, it adds <comma> <newline> <record>.

Whilst this makes the feed pretty to read, it doesn't make it easy to parse, as you basically need a full JSON stream parser to delimit the record. Or
else, you're always one record behind.

Wouldn't it be better to send the record followed by a newline, and then
<comma> <record> <newline> for the next one? That is,

{"results":[
{"seq":1,"id":"1f9bcccaadf2c3e9508d42532838595f","changes": [{"rev":"1-23202479633c2b380f79507a776743d5"}]} ,{"seq":2,"id":"291e49cc084d2e180f3a5d313d255889","changes": [{"rev":"1-3975759ccff3842adf690a5c10caee42"}]} ,{"seq":3,"id":"a6bdc0e451df85169178f0d9619b605a","changes": [{"rev":"1-027467bd0efec85f21c822a8eb537073"}]}
],
"last_seq":3}

Regards,

Brian.


Hi Brian, Matt Goodall brought this up last month too:

http://mail-archives.apache.org/mod_mbox/couchdb-dev/200907.mbox/%[email protected]%3e

I'm +1 on appending the newline immediately and moving the comma to the beginning of the next line.

Adam

Reply via email to