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/12/04 21:09:45 UTC
[14/22] couch commit: updated
refs/heads/2491-refactor-couch-httpd-auth to 3e8286d
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.
Conflicts:
src/couch_httpd_changes.erl
Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch/commit/071dedf1
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch/tree/071dedf1
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch/diff/071dedf1
Branch: refs/heads/2491-refactor-couch-httpd-auth
Commit: 071dedf1d35b6cd5f5bb0e553de7c81acc43954a
Parents: 7f2af21
Author: benoitc <be...@apache.org>
Authored: Sat Feb 8 21:27:58 2014 +0100
Committer: Benjamin Bastian <be...@gmail.com>
Committed: Fri Oct 31 12:43:53 2014 -0700
----------------------------------------------------------------------
src/couch_httpd_changes.erl | 40 +++++++++++++++++++++++++++-------------
1 file changed, 27 insertions(+), 13 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/071dedf1/src/couch_httpd_changes.erl
----------------------------------------------------------------------
diff --git a/src/couch_httpd_changes.erl b/src/couch_httpd_changes.erl
index 56ce559..b494b0d 100644
--- a/src/couch_httpd_changes.erl
+++ b/src/couch_httpd_changes.erl
@@ -201,9 +201,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,
@@ -220,16 +226,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">>, Db, NewLimit, Callback, Args}};
- true ->
- {stop, {<<"">>, Db, NewLimit, 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
@@ -256,7 +270,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
@@ -272,7 +286,7 @@ view_change_row(Db, DocInfo, Args) ->
end;
false ->
[]
- end}.
+ end}}.
parse_changes_query(Req, Db) ->
ChangesArgs = lists:foldl(fun({Key, Value}, Args) ->