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 722eb63b5deda4df680d51b853f081339bdc216e
Author: Paul J. Davis <[email protected]>
AuthorDate: Wed Nov 15 11:45:54 2017 -0600

    Move sorting logic to couch_key_tree.erl
---
 src/couch/src/couch_db.erl       | 8 +-------
 src/couch/src/couch_key_tree.erl | 9 +++++++++
 2 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/src/couch/src/couch_db.erl b/src/couch/src/couch_db.erl
index eb39c56..c352f3c 100644
--- a/src/couch/src/couch_db.erl
+++ b/src/couch/src/couch_db.erl
@@ -946,13 +946,7 @@ prep_and_validate_replicated_updates(Db, 
[Bucket|RestBuckets], [OldInfo|RestOldI
         OldLeafs = couch_key_tree:get_all_leafs_full(OldTree),
         OldLeafsLU = [{Start, RevId} || {Start, [{RevId, _}|_]} <- OldLeafs],
         NewPaths = lists:map(fun couch_doc:to_path/1, Bucket),
-        SortedPaths = lists:sort(NewPaths),
-        NewRevTree = lists:foldl(
-            fun(NewPath, AccTree) ->
-                {NewTree, _} = couch_key_tree:merge(AccTree, NewPath),
-                NewTree
-            end,
-            OldTree, SortedPaths),
+        NewRevTree = couch_key_tree:multi_merge(OldTree, NewPaths),
         Leafs = couch_key_tree:get_all_leafs_full(NewRevTree),
         LeafRevsFullDict = dict:from_list( [{{Start, RevId}, FullPath} || 
{Start, [{RevId, _}|_]}=FullPath <- Leafs]),
         {ValidatedBucket, AccErrors3} =
diff --git a/src/couch/src/couch_key_tree.erl b/src/couch/src/couch_key_tree.erl
index 2e722ba..d18ecbc 100644
--- a/src/couch/src/couch_key_tree.erl
+++ b/src/couch/src/couch_key_tree.erl
@@ -59,6 +59,7 @@ get_key_leafs/2,
 map/2,
 map_leafs/2,
 mapfold/3,
+multi_merge/2,
 merge/3,
 merge/2,
 remove_leafs/2,
@@ -72,6 +73,14 @@ full_stem/2
 -type revtree() :: [tree()].
 
 
+%% @doc Merge multiple paths into the given tree.
+-spec multi_merge(revtree(), tree()) -> revtree().
+multi_merge(RevTree, Trees) ->
+    lists:foldl(fun(Tree) ->
+        merge(RevTree, Tree)
+    end, RevTree, lists:sort(Trees)).
+
+
 %% @doc Merge a path into the given tree and then stem the result.
 %% Although Tree is of type tree(), it must not contain any branches.
 -spec merge(revtree(), tree(), pos_integer()) ->

-- 
To stop receiving notification emails like this one, please contact
"[email protected]" <[email protected]>.

Reply via email to