nickva commented on code in PR #4432:
URL: https://github.com/apache/couchdb/pull/4432#discussion_r1113333455
##########
src/couch_mrview/src/couch_mrview.erl:
##########
@@ -531,36 +531,45 @@ map_fold({{Key, Id}, Val}, _Offset, Acc) ->
user_acc = UAcc1,
last_go = Go
}};
-map_fold(#doc{id = <<"_local/", _/binary>>} = Doc, _Offset, #mracc{} = Acc) ->
- #mracc{
- limit = Limit,
- callback = Callback,
- user_acc = UAcc0,
- args = Args
- } = Acc,
- #doc{
- id = DocId,
- revs = {Pos, [RevId | _]}
- } = Doc,
- Rev = {Pos, RevId},
- Row =
- [
- {id, DocId},
- {key, DocId},
- {value, {[{rev, couch_doc:rev_to_str(Rev)}]}}
- ] ++
- if
- not Args#mrargs.include_docs -> [];
- true -> [{doc, couch_doc:to_json_obj(Doc,
Args#mrargs.doc_options)}]
- end,
- {Go, UAcc1} = Callback({row, Row}, UAcc0),
- {Go, Acc#mracc{
- limit = Limit - 1,
- reduce_fun = undefined,
- doc_info = undefined,
- user_acc = UAcc1,
- last_go = Go
- }}.
+map_fold(#doc{id = <<"_local/", IdTail/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>>} ->
+ {ok, Acc};
Review Comment:
One worry here could be if users have somehow created their own
`_local/purge-foo` documents (probably less of a chance they'd have a
`_local/shard-sync-foo`).
To be extra sure we are not hiding user docs we could inspect the doc
bodies. For instance, `purge-` clients would all have a `purge_seq`, and
`signature` fields and `shard-sync` checkpoints would have `target_uuid` and
`seq`. So we could check those with something like:
```erlang
...
case include_local(IncludeSys, Doc) of
true ->
... ;
false ->
{ok, Acc}
end
include_local(false, #doc{id = <<"_local/purge-", _/binary>>, body =
{Props}}) ->
not contains_fields([<<"purge_seq">>, <<"signature">>], Props);
include_local(false, #doc{id = <<"_local/shard-sync-", _/binary, body =
{Props}}) ->
not contains_fields([<<"target_uuid">>, <<"seq">>], Props);
include_local(_, #doc{}) ->
true.
contains_fields(Props, []) ->
false;
contains_fields(Props, [Field | Fields]) ->
case couch_util:get_value(Field, Props) of
undefined -> false;
_ -> contains_fields(Props, Fields)
end
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]