couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From beno...@apache.org
Subject couchdb commit: updated refs/heads/1994-merge-rcouch to 4357ef7
Date Sat, 08 Feb 2014 20:30:16 GMT
Updated Branches:
  refs/heads/1994-merge-rcouch 29b8a065e -> 4357ef76b


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/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/4357ef76
Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/4357ef76
Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/4357ef76

Branch: refs/heads/1994-merge-rcouch
Commit: 4357ef76bde008bc86c5d39b7b94e6a284b330fa
Parents: 29b8a06
Author: Benoit Chesneau <benoitc@apache.org>
Authored: Sat Feb 8 21:27:58 2014 +0100
Committer: Benoit Chesneau <benoitc@apache.org>
Committed: Sat Feb 8 21:27:58 2014 +0100

----------------------------------------------------------------------
 apps/couch_httpd/src/couch_httpd_changes.erl | 40 +++++++++++++++--------
 1 file changed, 27 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb/blob/4357ef76/apps/couch_httpd/src/couch_httpd_changes.erl
----------------------------------------------------------------------
diff --git a/apps/couch_httpd/src/couch_httpd_changes.erl b/apps/couch_httpd/src/couch_httpd_changes.erl
index 510e20a..1c4a147 100644
--- a/apps/couch_httpd/src/couch_httpd_changes.erl
+++ b/apps/couch_httpd/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) ->


Mime
View raw message