couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dav...@apache.org
Subject [couchdb] 03/04: Sort document updates to guarantee proper merging
Date Thu, 02 Nov 2017 19:32:17 GMT
This is an automated email from the ASF dual-hosted git repository.

davisp pushed a commit to branch optimize-doc-updates
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit bb559f9ea8ad544a6c958bec893ecea286aec229
Author: Paul J. Davis <paul.joseph.davis@gmail.com>
AuthorDate: Thu Nov 2 12:32:42 2017 -0500

    Sort document updates to guarantee proper merging
---
 src/couch/src/couch_db_updater.erl | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/src/couch/src/couch_db_updater.erl b/src/couch/src/couch_db_updater.erl
index 0daed90..bcddbe0 100644
--- a/src/couch/src/couch_db_updater.erl
+++ b/src/couch/src/couch_db_updater.erl
@@ -755,9 +755,15 @@ merge_rev_trees(_Limit, _Merge, [], [], AccNewInfos, AccRemoveSeqs, AccSeq)
->
 merge_rev_trees(Limit, MergeConflicts, [NewDocs|RestDocsList],
         [OldDocInfo|RestOldInfo], AccNewInfos, AccRemoveSeqs, AccSeq) ->
     erlang:put(last_id_merged, OldDocInfo#full_doc_info.id), % for debugging
+    SortFun = fun({_, #doc{revs={D1, R1}}}, {_, #doc{revs={D2, R2}}}) ->
+        A = {(D1 - length(R1)), lists:reverse(R1)},
+        B = {(D2 - length(R2)), lists:reverse(R2)},
+        A =< B
+    end,
+    SortedDocs = lists:sort(SortFun, NewDocs),
     NewDocInfo0 = lists:foldl(fun({Client, NewDoc}, OldInfoAcc) ->
         merge_rev_tree(OldInfoAcc, NewDoc, Client, MergeConflicts)
-    end, OldDocInfo, NewDocs),
+    end, OldDocInfo, SortedDocs),
     NewDocInfo1 = stem_full_doc_info(NewDocInfo0, Limit),
     % When MergeConflicts is false, we updated #full_doc_info.deleted on every
     % iteration of merge_rev_tree. However, merge_rev_tree does not update

-- 
To stop receiving notification emails like this one, please contact
"commits@couchdb.apache.org" <commits@couchdb.apache.org>.

Mime
View raw message