FAQ
view changes: handle case where the doc is deleted

With this change we also emit a changes when the doc is removed from the
view.


Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/commit/71654af7
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/tree/71654af7
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/diff/71654af7

Branch: refs/heads/1994-merge-rcouch
Commit: 71654af7cdd514ee6c11d2721b3397a92bd27146
Parents: 44a61c3
Author: benoitc <bchesneau@gmail.com>
Authored: Thu Jul 3 11:20:06 2014 +0200
Committer: benoitc <bchesneau@gmail.com>
Committed: Thu Jul 3 11:20:06 2014 +0200

----------------------------------------------------------------------
  src/couch_mrview_updater.erl | 22 ++++++++--------------
  1 file changed, 8 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/71654af7/src/couch_mrview_updater.erl
----------------------------------------------------------------------
diff --git a/src/couch_mrview_updater.erl b/src/couch_mrview_updater.erl
index d6f2713..4d51f78 100644
--- a/src/couch_mrview_updater.erl
+++ b/src/couch_mrview_updater.erl
@@ -254,10 +254,13 @@ insert_results(DocId, Seq, [KVs | RKVs], [{Id, {VKVs, SKVs}} | RVKVs], VKVAcc,
  log_removed([], _, Log) ->
      Log;
  log_removed([{ok, {DocId, VIdKeys}} | Rest], Seq, Log) ->
- Log2 = lists:foldl(fun({Id, Keys}, Log1) ->
+ Log2 = lists:foldl(fun
+ ({Id, Keys}, Log1) when is_list(Keys) ->
                      lists:foldl(fun(Key, Log3) ->
                                  dict:append(DocId, {Id, {Key, Seq, del}}, Log3)
- end, Log1, Keys)
+ end, Log1, Keys);
+ ({Id, Key}, Log1) ->
+ dict:append(DocId, {Id, {Key, Seq, del}}, Log1)
              end, Log, VIdKeys),
      log_removed(Rest, Seq, Log2);
  log_removed([_ | Rest], Seq, Log) ->
@@ -366,7 +369,7 @@ update_log(Btree, Log, UpdatedSeq, _) ->
      RemValue = {[{<<"_removed">>, true}]},
      {Log1, AddAcc, DelAcc} = walk_log(Btree, fun({DocId, VIdKeys}, {Log2, AddAcc2, DelAcc2}) ->

- {Log3, AddAcc3, DelAcc3} = lists:foldl(fun({ViewId,{Key, Seq, Op}},
+ {Log3, AddAcc3, DelAcc3} = lists:foldl(fun({ViewId,{Key, Seq,_Op}},
                                                             {Log4, AddAcc4, DelAcc4}) ->

                              IsUpdated = lists:member({DocId, ViewId, Key},
@@ -393,7 +396,7 @@ update_log(Btree, Log, UpdatedSeq, _) ->
                                                          AddAcc4)
                                      end,
                                      {Log4, AddAcc5, DelAcc5};
- false when Op /= del ->
+ false ->
                                      %% an update operation has been
                                      %% logged for this key. We must now
                                      %% record it as deleted in the
@@ -411,16 +414,7 @@ update_log(Btree, Log, UpdatedSeq, _) ->
                                                            {{UpdatedSeq, Key},
                                                             {DocId, RemValue}},
                                                            AddAcc4),
- {Log5, AddAcc5, DelAcc5};
- false ->
- %% the key has already been
- %% registered in the view as
- %% deleted, make sure to add it
- %% to the new log.
- Log5 = dict:append(DocId,
- {ViewId,
- {Key, Seq, del}}, Log4),
- {Log5, AddAcc4, DelAcc4}
+ {Log5, AddAcc5, DelAcc5}
                              end
                      end, {Log2, AddAcc2, DelAcc2}, VIdKeys),
                      {ok, {Log3, AddAcc3, DelAcc3}}

Search Discussions

Discussion Posts

Previous

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 4 of 7 | next ›
Discussion Overview
groupcommits @
categoriescouchdb
postedJul 13, '14 at 12:29p
activeJul 13, '14 at 12:29p
posts7
users1
websitecouchdb.apache.org
irc#couchdb

1 user in discussion

Benoitc: 7 posts

People

Translate

site design / logo © 2021 Grokbase