You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by da...@apache.org on 2014/02/13 04:10:09 UTC
[13/14] couch-httpd commit: updated refs/heads/1994-merge-rcouch to
d936233
couch_httpd_changes: check removed keys from the view filter
Make sure to only emit deleted document when a deleted key is passed to
the view filter.
Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch-httpd/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch-httpd/commit/792797f3
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-httpd/tree/792797f3
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-httpd/diff/792797f3
Branch: refs/heads/1994-merge-rcouch
Commit: 792797f394dfe95eb1195b2da37de57dc7dc0d56
Parents: c1d2f8f
Author: benoitc <be...@apache.org>
Authored: Sat Feb 8 21:27:58 2014 +0100
Committer: Paul J. Davis <pa...@gmail.com>
Committed: Wed Feb 12 21:05:52 2014 -0600
----------------------------------------------------------------------
src/couch_httpd_changes.erl | 40 +++++++++++++++++++++++++++-------------
1 file changed, 27 insertions(+), 13 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb-couch-httpd/blob/792797f3/src/couch_httpd_changes.erl
----------------------------------------------------------------------
diff --git a/src/couch_httpd_changes.erl b/src/couch_httpd_changes.erl
index 510e20a..1c4a147 100644
--- a/src/couch_httpd_changes.erl
+++ b/src/couch_httpd_changes.erl
@@ -213,9 +213,15 @@ view_changes_cb(stop, {LastSeq, {_, _, _, Callback, Args}}) ->
view_changes_cb(heartbeat, {_, _, _, Callback, Args}=Acc) ->
Callback(timeout, Args#changes_args.feed),
{ok, Acc};
-view_changes_cb({{Seq, _Key, DocId}, _VAl},
+view_changes_cb({{Seq, _Key, DocId}, Val},
{Prepend, OldLimit, Db0, Callback, Args}=Acc) ->
+ %% is the key removed from the index?
+ Removed = case Val of
+ {[{<<"_removed">>, true}]} -> true;
+ _ -> false
+ end,
+
#changes_args{
feed = ResponseType,
limit = Limit} = Args,
@@ -232,16 +238,24 @@ view_changes_cb({{Seq, _Key, DocId}, _VAl},
case couch_db:get_doc_info(Db, DocId) of
{ok, DocInfo} ->
%% get change row
- ChangeRow = view_change_row(Db, DocInfo, Args),
- %% emit change row
- Callback({change, ChangeRow, Prepend}, ResponseType),
-
- %% if we achieved the limit, stop here, else continue.
- NewLimit = OldLimit + 1,
- if Limit > NewLimit ->
- {ok, {<<",\n">>, NewLimit, Db, Callback, Args}};
- true ->
- {stop, {<<"">>, NewLimit, Db, Callback, Args}}
+ {Deleted, ChangeRow} = view_change_row(Db, DocInfo, Args),
+
+ case Removed of
+ true when Deleted /= true ->
+ %% the key has been removed from the view but the
+ %% document hasn't been deleted so ignore it.
+ {ok, Acc};
+ _ ->
+ %% emit change row
+ Callback({change, ChangeRow, Prepend}, ResponseType),
+
+ %% if we achieved the limit, stop here, else continue.
+ NewLimit = OldLimit + 1,
+ if Limit > NewLimit ->
+ {ok, {<<",\n">>, NewLimit, Db, Callback, Args}};
+ true ->
+ {stop, {<<"">>, NewLimit, Db, Callback, Args}}
+ end
end;
{error, not_found} ->
%% doc not found, continue
@@ -268,7 +282,7 @@ view_change_row(Db, DocInfo, Args) ->
|| #rev_info{rev=R} <- Revs]
end,
- {[{<<"seq">>, Seq}, {<<"id">>, Id}, {<<"changes">>, Changes}] ++
+ {Del, {[{<<"seq">>, Seq}, {<<"id">>, Id}, {<<"changes">>, Changes}] ++
deleted_item(Del) ++ case InDoc of
true ->
Opts = case Conflicts of
@@ -284,7 +298,7 @@ view_change_row(Db, DocInfo, Args) ->
end;
false ->
[]
- end}.
+ end}}.
parse_changes_query(Req, Db) ->
ChangesArgs = lists:foldl(fun({Key, Value}, Args) ->