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 2023/02/24 22:07:37 UTC

[couchdb] 02/04: inspect the document more precisely to avoid skipping user docs

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

vatamane pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit b702a5edff969abac0628e0cf16ef6412ba5c292
Author: Christian Kruse <cj...@defunct.ch>
AuthorDate: Tue Feb 21 20:45:19 2023 +0100

    inspect the document more precisely to avoid skipping user docs
---
 src/couch_mrview/src/couch_mrview.erl | 27 ++++++++++++++++++++++-----
 1 file changed, 22 insertions(+), 5 deletions(-)

diff --git a/src/couch_mrview/src/couch_mrview.erl b/src/couch_mrview/src/couch_mrview.erl
index 3616af7df..c0f6ff49b 100644
--- a/src/couch_mrview/src/couch_mrview.erl
+++ b/src/couch_mrview/src/couch_mrview.erl
@@ -531,13 +531,11 @@ map_fold({{Key, Id}, Val}, _Offset, Acc) ->
         user_acc = UAcc1,
         last_go = Go
     }};
-map_fold(#doc{id = <<"_local/", IdTail/binary>>} = Doc, _Offset, #mracc{} = Acc) ->
+map_fold(#doc{id = <<"_local/", _/binary>>} = Doc, _Offset, #mracc{} = Acc) ->
     IncludeSys = couch_util:get_value(include_system, Acc#mracc.args#mrargs.extra),
 
-    case {IncludeSys, IdTail} of
-        {false, <<"purge-", _/binary>>} ->
-            {ok, Acc};
-        {false, <<"shard-sync", _/binary>>} ->
+    case should_skip_local_document(IncludeSys, Doc) of
+        true ->
             {ok, Acc};
         _ ->
             #mracc{
@@ -571,6 +569,25 @@ map_fold(#doc{id = <<"_local/", IdTail/binary>>} = Doc, _Offset, #mracc{} = Acc)
             }}
     end.
 
+should_skip_local_document(_IncludeSys = false, #doc{
+    id = <<"_local/purge-", _/binary>>, body = {Props}
+}) ->
+    contains_fields([<<"purge_seq">>], Props);
+should_skip_local_document(_IncludeSys = false, #doc{
+    id = <<"_local/shard-sync", _/binary>>, body = {Props}
+}) ->
+    contains_fields([<<"target_uuid">>, <<"seq">>], Props);
+should_skip_local_document(_IncludeSys, _Doc) ->
+    false.
+
+contains_fields([], _Props) ->
+    true;
+contains_fields([Field | Fields], Props) ->
+    case couch_util:get_value(Field, Props) of
+        undefined -> false;
+        _ -> contains_fields(Fields, Props)
+    end.
+
 red_fold(Db, {NthRed, _Lang, View} = RedView, Args, Callback, UAcc) ->
     Finalizer =
         case couch_util:get_value(finalizer, Args#mrargs.extra) of