summaryrefslogtreecommitdiff
path: root/src/couchdb/couch_db.erl
diff options
context:
space:
mode:
authorDamien F. Katz <damien@apache.org>2008-04-23 00:25:23 +0000
committerDamien F. Katz <damien@apache.org>2008-04-23 00:25:23 +0000
commit689f9830b50ac6b7a673ce467626c6d2deef645c (patch)
tree2a321ba63b940883d1b4373a34dc181709c4e92a /src/couchdb/couch_db.erl
parent6949f81ae419c5d10131c71732ca0637ef7d234d (diff)
Replicator optmizations and fix for unnecessary document copy during re-replication
git-svn-id: https://svn.apache.org/repos/asf/incubator/couchdb/trunk@650705 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/couchdb/couch_db.erl')
-rw-r--r--src/couchdb/couch_db.erl73
1 files changed, 41 insertions, 32 deletions
diff --git a/src/couchdb/couch_db.erl b/src/couchdb/couch_db.erl
index 289cc4f9..b45a1ff4 100644
--- a/src/couchdb/couch_db.erl
+++ b/src/couchdb/couch_db.erl
@@ -133,7 +133,8 @@ open_doc(MainPid, Id, Options) ->
end.
open_doc_revs(MainPid, Id, Revs, Options) ->
- open_doc_revs_int(get_db(MainPid), Id, Revs, Options).
+ [Result] = open_doc_revs_int(get_db(MainPid), [{Id, Revs}], Options),
+ Result.
get_missing_revs(MainPid, IdRevsList) ->
Ids = [Id1 || {Id1, _Revs} <- IdRevsList],
@@ -148,7 +149,9 @@ get_missing_revs(MainPid, IdRevsList) ->
end
end,
IdRevsList, FullDocInfoResults),
- {ok, Results}.
+ % strip out the non-missing ids
+ Missing = [{Id, Revs} || {Id, Revs} <- Results, Revs /= []],
+ {ok, Missing}.
get_doc_info(Db, Id) ->
case get_full_doc_info(Db, Id) of
@@ -563,38 +566,44 @@ get_db(MainPid) ->
{ok, Db} = gen_server:call(MainPid, get_db),
Db.
-open_doc_revs_int(Db, Id, Revs, Options) ->
- case get_full_doc_info(Db, Id) of
- {ok, #full_doc_info{rev_tree=RevTree}} ->
- {FoundRevs, MissingRevs} =
- case Revs of
- all ->
- {couch_key_tree:get_all_leafs(RevTree), []};
- _ ->
- case lists:member(latest, Options) of
- true ->
- couch_key_tree:get_key_leafs(RevTree, Revs);
- false ->
- couch_key_tree:get(RevTree, Revs)
+open_doc_revs_int(Db, IdRevs, Options) ->
+ Ids = [Id || {Id, _Revs} <- IdRevs],
+ LookupResults = get_full_doc_infos(Db, Ids),
+ lists:zipwith(
+ fun({Id, Revs}, Lookup) ->
+ case Lookup of
+ {ok, #full_doc_info{rev_tree=RevTree}} ->
+ {FoundRevs, MissingRevs} =
+ case Revs of
+ all ->
+ {couch_key_tree:get_all_leafs(RevTree), []};
+ _ ->
+ case lists:member(latest, Options) of
+ true ->
+ couch_key_tree:get_key_leafs(RevTree, Revs);
+ false ->
+ couch_key_tree:get(RevTree, Revs)
+ end
+ end,
+ FoundResults =
+ lists:map(fun({Rev, Value, FoundRevPath}) ->
+ case Value of
+ ?REV_MISSING ->
+ % we have the rev in our list but know nothing about it
+ {{not_found, missing}, Rev};
+ {IsDeleted, SummaryPtr} ->
+ {ok, make_doc(Db, Id, IsDeleted, SummaryPtr, FoundRevPath)}
+ end
+ end, FoundRevs),
+ Results = FoundResults ++ [{{not_found, missing}, MissingRev} || MissingRev <- MissingRevs],
+ {ok, Results};
+ not_found when Revs == all ->
+ {ok, []};
+ not_found ->
+ {ok, [{{not_found, missing}, Rev} || Rev <- Revs]}
end
end,
- FoundResults =
- lists:map(fun({Rev, Value, FoundRevPath}) ->
- case Value of
- ?REV_MISSING ->
- % we have the rev in our list but know nothing about it
- {{not_found, missing}, Rev};
- {IsDeleted, SummaryPtr} ->
- {ok, make_doc(Db, Id, IsDeleted, SummaryPtr, FoundRevPath)}
- end
- end, FoundRevs),
- Results = FoundResults ++ [{{not_found, missing}, MissingRev} || MissingRev <- MissingRevs],
- {ok, Results};
- not_found when Revs == all ->
- {ok, []};
- not_found ->
- {ok, [{{not_found, missing}, Rev} || Rev <- Revs]}
- end.
+ IdRevs, LookupResults).
open_doc_int(Db, ?LOCAL_DOC_PREFIX ++ _ = Id, _Options) ->
case couch_btree:lookup(Db#db.local_docs_btree, [Id]) of