Fixes for _local doc update and _bulk_docs operations with new_edits false #1683
Conversation
src/couch/src/couch_db_updater.erl
Outdated
} | ||
end, Docs). | ||
lists:foldl(fun({Client, NewDoc}, Acc) -> | ||
try |
iilyak
Oct 25, 2018
•
Contributor
WARNING: Most likely very subjective proposal. How about creating a function increment_revision(#doc{}) -> #doc{} | undefined
and put try/catch there. Then we can rewrite foldl as follows:
lists:foldl(fun({Client, NewDoc}, Acc) ->
case increment_revision(NewDoc) of
#doc{revs = {0, [NewRev | _]}} = Doc ->
send_result(Client, Doc, {ok, {0, integer_to_binary(NewRev)}}),
[Doc | Acc];
_ ->
send_result(Client, NewDoc, {error, <<"Invalid rev format">>}),
Acc
end
end, [], Docs).
WARNING: Most likely very subjective proposal. How about creating a function increment_revision(#doc{}) -> #doc{} | undefined
and put try/catch there. Then we can rewrite foldl as follows:
lists:foldl(fun({Client, NewDoc}, Acc) ->
case increment_revision(NewDoc) of
#doc{revs = {0, [NewRev | _]}} = Doc ->
send_result(Client, Doc, {ok, {0, integer_to_binary(NewRev)}}),
[Doc | Acc];
_ ->
send_result(Client, NewDoc, {error, <<"Invalid rev format">>}),
Acc
end
end, [], Docs).
end, Bucket) | ||
end, BucketList), | ||
|
||
ValidatePred = fun |
iilyak
Oct 26, 2018
Contributor
💯
Doc = #doc{ | ||
id = <<"_local/alice">>, | ||
revs = {0, [<<"1">>]}, | ||
meta = [{ref, make_ref()}] |
iilyak
Oct 26, 2018
Contributor
interesting approach
interesting approach
+1. Nice work New tests pass. Had to update commands for manual tests to include ContentType and auth. Everything works as advertised. |
@iilyak I've extracted |
Perfect. Thank you @eiri. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Overview
This PR is mostly a refactoring and addresses the following issues:
badarg
exception._local
prefix written into a wrong btree on a bulk operation withnew_edits
set tofalse
.new_edits
set tofalse
Testing recommendations
New tests are expected to pass.
For manual testing here is an expected change of behaviour:
Readable error on an invalid rev for a local doc creation
Correct creation of a local doc on a bulk update
Generation of a missing id on a bulk update
Related Issues or Pull Requests
This closes #1628
Checklist