summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFilipe David Borba Manana <fdmanana@apache.org>2011-01-17 11:49:00 +0000
committerFilipe David Borba Manana <fdmanana@apache.org>2011-01-17 11:49:00 +0000
commit84052a85cd93d07a324b3e77c97f2a9552b05f93 (patch)
tree60190a56736d05a8fe36f7955e29a691817bad6a /src
parent18d16e55265d5017331d5b40726e3defed949e06 (diff)
Merged revision 1059893 from trunk
More efficient implementation of the DB updater BTree functions Closes COUCHDB-1027 git-svn-id: https://svn.apache.org/repos/asf/couchdb/branches/1.1.x@1059894 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src')
-rw-r--r--src/couchdb/couch_db_updater.erl32
1 files changed, 21 insertions, 11 deletions
diff --git a/src/couchdb/couch_db_updater.erl b/src/couchdb/couch_db_updater.erl
index bac31a8e..c14d6bf9 100644
--- a/src/couchdb/couch_db_updater.erl
+++ b/src/couchdb/couch_db_updater.erl
@@ -282,11 +282,14 @@ collect_updates(GroupedDocsAcc, ClientsAcc, MergeConflicts, FullCommit) ->
btree_by_seq_split(#doc_info{id=Id, high_seq=KeySeq, revs=Revs}) ->
- RevInfos = [{Rev, Seq, Bp} ||
- #rev_info{rev=Rev,seq=Seq,deleted=false,body_sp=Bp} <- Revs],
- DeletedRevInfos = [{Rev, Seq, Bp} ||
- #rev_info{rev=Rev,seq=Seq,deleted=true,body_sp=Bp} <- Revs],
- {KeySeq,{Id, RevInfos, DeletedRevInfos}}.
+ {RevInfos, DeletedRevInfos} = lists:foldl(
+ fun(#rev_info{deleted = false, seq = Seq} = Ri, {Acc, AccDel}) ->
+ {[{Ri#rev_info.rev, Seq, Ri#rev_info.body_sp} | Acc], AccDel};
+ (#rev_info{deleted = true, seq = Seq} = Ri, {Acc, AccDel}) ->
+ {Acc, [{Ri#rev_info.rev, Seq, Ri#rev_info.body_sp} | AccDel]}
+ end,
+ {[], []}, Revs),
+ {KeySeq, {Id, lists:reverse(RevInfos), lists:reverse(DeletedRevInfos)}}.
btree_by_seq_join(KeySeq, {Id, RevInfos, DeletedRevInfos}) ->
#doc_info{
@@ -340,12 +343,19 @@ btree_by_id_join(Id, {HighSeq, Deleted, DiskTree}) ->
#full_doc_info{id=Id, update_seq=HighSeq, deleted=Deleted==1, rev_tree=Tree}.
btree_by_id_reduce(reduce, FullDocInfos) ->
- % count the number of not deleted documents
- {length([1 || #full_doc_info{deleted=false} <- FullDocInfos]),
- length([1 || #full_doc_info{deleted=true} <- FullDocInfos])};
-btree_by_id_reduce(rereduce, Reds) ->
- {lists:sum([Count || {Count,_} <- Reds]),
- lists:sum([DelCount || {_, DelCount} <- Reds])}.
+ lists:foldl(
+ fun(#full_doc_info{deleted = false}, {NotDeleted, Deleted}) ->
+ {NotDeleted + 1, Deleted};
+ (#full_doc_info{deleted = true}, {NotDeleted, Deleted}) ->
+ {NotDeleted, Deleted + 1}
+ end,
+ {0, 0}, FullDocInfos);
+btree_by_id_reduce(rereduce, [FirstRed | RestReds]) ->
+ lists:foldl(
+ fun({NotDeleted, Deleted}, {AccNotDeleted, AccDeleted}) ->
+ {AccNotDeleted + NotDeleted, AccDeleted + Deleted}
+ end,
+ FirstRed, RestReds).
btree_by_seq_reduce(reduce, DocInfos) ->
% count the number of documents