diff options
author | John Christopher Anderson <jchris@apache.org> | 2009-09-14 20:20:50 +0000 |
---|---|---|
committer | John Christopher Anderson <jchris@apache.org> | 2009-09-14 20:20:50 +0000 |
commit | 159ce7f416c430137b2b71f0ef6ffbb6a5c8f2ec (patch) | |
tree | 963717120b2f360765b18a8507a4828e9c5e9c4a /src/couchdb | |
parent | 89fc389a328c54efbc03c4cbf56dc363db7e97f7 (diff) |
finish committing my changes adventure. pardon the dust.
git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@814828 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/couchdb')
-rw-r--r-- | src/couchdb/couch_httpd_db.erl | 26 | ||||
-rw-r--r-- | src/couchdb/couch_httpd_view.erl | 2 | ||||
-rw-r--r-- | src/couchdb/couch_rep_changes_feed.erl | 8 |
3 files changed, 21 insertions, 15 deletions
diff --git a/src/couchdb/couch_httpd_db.erl b/src/couchdb/couch_httpd_db.erl index d0960936..2e0a2fdb 100644 --- a/src/couchdb/couch_httpd_db.erl +++ b/src/couchdb/couch_httpd_db.erl @@ -74,11 +74,13 @@ start_sending_changes(Resp, _Else) -> handle_changes_req(#httpd{method='GET',path_parts=[DbName|_]}=Req, Db) -> {FilterFun, EndFilterFun} = make_filter_funs(Req, Db), + {ok, Info} = couch_db:get_db_info(Db), + Seq = proplists:get_value(update_seq, Info), {Dir, StartSeq} = case couch_httpd:qs_value(Req, "descending", "false") of "false" -> {fwd, list_to_integer(couch_httpd:qs_value(Req, "since", "0"))}; "true" -> - {rev, 1000000000000000}; % super big value, should use current db seq + {rev, Seq}; _Bad -> throw({bad_request, "descending must be true or false"}) end, ResponseType = couch_httpd:qs_value(Req, "feed", "normal"), @@ -104,7 +106,6 @@ handle_changes_req(#httpd{method='GET',path_parts=[DbName|_]}=Req, Db) -> get_rest_db_updated() % clean out any remaining update messages end; true -> - {ok, Info} = couch_db:get_db_info(Db), CurrentEtag = couch_httpd:make_etag(Info), couch_httpd:etag_respond(Req, CurrentEtag, fun() -> % send the etag @@ -162,19 +163,19 @@ keep_sending_changes(#httpd{user_ctx=UserCtx,path_parts=[DbName|_]}=Req, Resp, end. changes_enumerator(DocInfos, {Db, _, _, FilterFun, Resp, "continuous", IncludeDocs}) -> - [#doc_info{id=Id, high_seq=Seq, revs=[#rev_info{rev=Rev}|_]}|_] = DocInfos, + [#doc_info{id=Id, high_seq=Seq, revs=[#rev_info{deleted=Del,rev=Rev}|_]}|_] = DocInfos, Results0 = [FilterFun(DocInfo) || DocInfo <- DocInfos], Results = [Result || Result <- Results0, Result /= null], case Results of [] -> {ok, {Db, Seq, nil, FilterFun, Resp, "continuous", IncludeDocs}}; _ -> - send_chunk(Resp, [?JSON_ENCODE(changes_row(Db, Seq, Id, Results, Rev, IncludeDocs)) + send_chunk(Resp, [?JSON_ENCODE(changes_row(Db, Seq, Id, Del, Results, Rev, IncludeDocs)) |"\n"]), {ok, {Db, Seq, nil, FilterFun, Resp, "continuous", IncludeDocs}} end; changes_enumerator(DocInfos, {Db, _, Prepend, FilterFun, Resp, _, IncludeDocs}) -> - [#doc_info{id=Id, high_seq=Seq, revs=[#rev_info{rev=Rev}|_]}|_] = DocInfos, + [#doc_info{id=Id, high_seq=Seq, revs=[#rev_info{deleted=Del,rev=Rev}|_]}|_] = DocInfos, Results0 = [FilterFun(DocInfo) || DocInfo <- DocInfos], Results = [Result || Result <- Results0, Result /= null], case Results of @@ -182,17 +183,18 @@ changes_enumerator(DocInfos, {Db, _, Prepend, FilterFun, Resp, _, IncludeDocs}) {ok, {Db, Seq, Prepend, FilterFun, Resp, nil, IncludeDocs}}; _ -> send_chunk(Resp, [Prepend, ?JSON_ENCODE( - changes_row(Db, Seq, Id, Results, Rev, IncludeDocs))]), + changes_row(Db, Seq, Id, Del, Results, Rev, IncludeDocs))]), {ok, {Db, Seq, <<",\n">>, FilterFun, Resp, nil, IncludeDocs}} end. -changes_row(Db, Seq, Id, Results, Rev, true) -> - {[{seq,Seq},{id,Id}, - {changes,Results}] ++ +changes_row(Db, Seq, Id, Del, Results, Rev, true) -> + {[{seq,Seq},{id,Id},{changes,Results}] ++ deleted_item(Del) ++ couch_httpd_view:doc_member(Db, Id, Rev)}; -changes_row(_, Seq, Id, Results, _, false) -> - {[{seq,Seq},{id,Id}, - {changes,Results}]}. +changes_row(_, Seq, Id, Del, Results, _, false) -> + {[{seq,Seq},{id,Id},{changes,Results}] ++ deleted_item(Del)}. + +deleted_item(true) -> [{deleted,true}]; +deleted_item(_) -> []. send_changes(Req, Resp, Db, Dir, StartSeq, Prepend, ResponseType, FilterFun, End) -> Style = list_to_existing_atom( diff --git a/src/couchdb/couch_httpd_view.erl b/src/couchdb/couch_httpd_view.erl index 5d7b396a..ba2a004a 100644 --- a/src/couchdb/couch_httpd_view.erl +++ b/src/couchdb/couch_httpd_view.erl @@ -603,7 +603,7 @@ doc_member(Db, DocId, Rev) -> JsonDoc = couch_doc:to_json_obj(Doc, []), [{doc, JsonDoc}]; _Else -> - [{error, missing}] + [{doc, null}] end. diff --git a/src/couchdb/couch_rep_changes_feed.erl b/src/couchdb/couch_rep_changes_feed.erl index f301b6e7..a89756e0 100644 --- a/src/couchdb/couch_rep_changes_feed.erl +++ b/src/couchdb/couch_rep_changes_feed.erl @@ -277,9 +277,13 @@ by_seq_loop(Server, Source, StartSeq) -> decode_row(<<",\n", Rest/binary>>) -> decode_row(Rest); decode_row(Row) -> - {[Seq, Id, {<<"changes">>,C}]} = ?JSON_DECODE(Row), + {Props} = ?JSON_DECODE(Row), + % [Seq, Id, {<<"changes">>,C}] + Seq = proplists:get_value(<<"seq">>, Props), + Id = proplists:get_value(<<"id">>, Props), + C = proplists:get_value(<<"changes">>, Props), C2 = [{[{<<"rev">>,couch_doc:parse_rev(R)}]} || {[{<<"rev">>,R}]} <- C], - {[Seq, Id, {<<"changes">>,C2}]}. + {[{<<"seq">>, Seq}, {<<"id">>,Id}, {<<"changes">>,C2}]}. flush_updated_messages() -> receive updated -> flush_updated_messages() |