You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by va...@apache.org on 2019/08/29 15:09:24 UTC

[couchdb] branch prototype/fdb-layer-ignore-local-docs-in-bdu created (now 68a6d5e)

This is an automated email from the ASF dual-hosted git repository.

vatamane pushed a change to branch prototype/fdb-layer-ignore-local-docs-in-bdu
in repository https://gitbox.apache.org/repos/asf/couchdb.git.


      at 68a6d5e  Skip before_doc_update processing for local docs

This branch includes the following new commits:

     new 68a6d5e  Skip before_doc_update processing for local docs

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[couchdb] 01/01: Skip before_doc_update processing for local docs

Posted by va...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

vatamane pushed a commit to branch prototype/fdb-layer-ignore-local-docs-in-bdu
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 68a6d5e1ba2851c04958792be00a35e16967773c
Author: Nick Vatamaniuc <va...@apache.org>
AuthorDate: Thu Aug 29 11:03:26 2019 -0400

    Skip before_doc_update processing for local docs
    
    This matches behavior on master:
    
    https://github.com/apache/couchdb/blob/master/src/couch/src/couch_db.erl#L1373-L1387
---
 src/fabric/src/fabric2_db_plugin.erl       |  7 +++++++
 src/fabric/test/fabric2_doc_crud_tests.erl | 24 +++++++++++++++++++++++-
 2 files changed, 30 insertions(+), 1 deletion(-)

diff --git a/src/fabric/src/fabric2_db_plugin.erl b/src/fabric/src/fabric2_db_plugin.erl
index 41f9e9d..cb824d7 100644
--- a/src/fabric/src/fabric2_db_plugin.erl
+++ b/src/fabric/src/fabric2_db_plugin.erl
@@ -21,6 +21,10 @@
     is_valid_purge_client/2
 ]).
 
+
+-include_lib("couch/include/couch_db.hrl").
+
+
 -define(SERVICE_ID, fabric2_db).
 
 
@@ -32,6 +36,9 @@ validate_dbname(DbName, Normalized, Default) ->
     maybe_handle(validate_dbname, [DbName, Normalized], Default).
 
 
+before_doc_update(_, #doc{id = <<?LOCAL_DOC_PREFIX, _/binary>>} = Doc, _) ->
+    Doc;
+
 before_doc_update(Db, Doc0, UpdateType) ->
     Fun = fabric2_db:get_before_doc_update_fun(Db),
     case with_pipe(before_doc_update, [Doc0, Db, UpdateType]) of
diff --git a/src/fabric/test/fabric2_doc_crud_tests.erl b/src/fabric/test/fabric2_doc_crud_tests.erl
index c19c474..3cb3808 100644
--- a/src/fabric/test/fabric2_doc_crud_tests.erl
+++ b/src/fabric/test/fabric2_doc_crud_tests.erl
@@ -60,7 +60,8 @@ doc_crud_test_() ->
                 fun delete_local_doc_basic/1,
                 fun recreate_local_doc/1,
                 fun create_local_doc_bad_rev/1,
-                fun create_local_doc_random_rev/1
+                fun create_local_doc_random_rev/1,
+                fun before_doc_update_skips_local_docs/1
             ]}
         }
     }.
@@ -762,3 +763,24 @@ create_local_doc_random_rev({Db, _}) ->
     ?assertEqual({ok, {0, <<"2">>}}, fabric2_db:update_doc(Db, Doc5)),
     {ok, Doc6} = fabric2_db:open_doc(Db, LDocId, []),
     ?assertEqual(Doc5#doc{revs = {0, [<<"2">>]}}, Doc6).
+
+
+before_doc_update_skips_local_docs({Db0, _}) ->
+
+    BduFun = fun(Doc, _, _) ->
+        Doc#doc{body = {[<<"bdu_was_here">>, true]}}
+    end,
+
+    Db = Db0#{before_doc_update := BduFun},
+
+    LDoc1 = #doc{id = <<"_local/ldoc1">>},
+    Doc1 = #doc{id = <<"doc1">>},
+
+    ?assertMatch({ok, {_, _}}, fabric2_db:update_doc(Db, LDoc1)),
+    ?assertMatch({ok, {_, _}}, fabric2_db:update_doc(Db, Doc1)),
+
+    {ok, LDoc2} = fabric2_db:open_doc(Db, LDoc1#doc.id),
+    {ok, Doc2} = fabric2_db:open_doc(Db, Doc1#doc.id),
+
+    ?assertEqual({[]}, LDoc2#doc.body),
+    ?assertEqual({[<<"bdu_was_here">>, true]}, Doc2#doc.body).