iilyak commented on a change in pull request #1683: Fixes for _local doc update and _bulk_docs operations with new_edits false URL: https://github.com/apache/couchdb/pull/1683#discussion_r228298764
########## File path: src/couch/src/couch_db_updater.erl ########## @@ -627,28 +627,35 @@ update_docs_int(Db, DocsList, LocalDocs, MergeConflicts, FullCommit) -> update_local_doc_revs(Docs) -> - lists:map(fun({Client, NewDoc}) -> - #doc{ - deleted = Delete, - revs = {0, PrevRevs} - } = NewDoc, - case PrevRevs of - [RevStr | _] -> - PrevRev = binary_to_integer(RevStr); - [] -> - PrevRev = 0 - end, - NewRev = case Delete of - false -> - PrevRev + 1; - true -> - 0 - end, - send_result(Client, NewDoc, {ok, {0, integer_to_binary(NewRev)}}), - NewDoc#doc{ - revs = {0, [NewRev]} - } - end, Docs). + lists:foldl(fun({Client, NewDoc}, Acc) -> + try Review comment: 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). ``` ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services