summaryrefslogtreecommitdiff
path: root/src/couchdb/couch_doc.erl
diff options
context:
space:
mode:
authorDamien F. Katz <damien@apache.org>2009-05-06 19:11:10 +0000
committerDamien F. Katz <damien@apache.org>2009-05-06 19:11:10 +0000
commit4b5e0a20aa087dd26df644c0432627aa3e5826d4 (patch)
tree1494b164fdef4004bff44aa39edbc2f1bf60d8f3 /src/couchdb/couch_doc.erl
parent887c9b1a8b551272c3ca06906cfdc4fb901830a8 (diff)
First cut at _changes api. Update the by_id and by_seq indexes to contain update seq numbers and pointers to bodies on disk, for use in the _changes api. This is a new file version, but the code can continue to serve the old 0.9 version without problems, though certain features in the _changes api will not be able to work. Upgrade to new file version (from 1 to 2) by compacting the file. Also fixed bugs with how the stats api tracks open databases.
git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@772406 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/couchdb/couch_doc.erl')
-rw-r--r--src/couchdb/couch_doc.erl50
1 files changed, 22 insertions, 28 deletions
diff --git a/src/couchdb/couch_doc.erl b/src/couchdb/couch_doc.erl
index 307f7372..4d2affa4 100644
--- a/src/couchdb/couch_doc.erl
+++ b/src/couchdb/couch_doc.erl
@@ -226,34 +226,28 @@ to_doc_info(FullDocInfo) ->
{DocInfo, _Path} = to_doc_info_path(FullDocInfo),
DocInfo.
-to_doc_info_path(#full_doc_info{id=Id,update_seq=Seq,rev_tree=Tree}) ->
- LeafRevs = couch_key_tree:get_all_leafs(Tree),
- SortedLeafRevs =
- lists:sort(fun({{IsDeletedA, _}, {StartA, [RevIdA|_]}}, {{IsDeletedB, _}, {StartB, [RevIdB|_]}}) ->
- % sort descending by {not deleted, then Depth, then RevisionId}
- A = {not IsDeletedA, StartA, RevIdA},
- B = {not IsDeletedB, StartB, RevIdB},
- A > B
- end,
- LeafRevs),
-
- [{{IsDeleted, SummaryPointer}, {Start, [RevId|_]}=Path} | Rest] = SortedLeafRevs,
- {ConflictRevTuples, DeletedConflictRevTuples} =
- lists:splitwith(fun({{IsDeleted1, _Sp}, _}) ->
- not IsDeleted1
- end, Rest),
-
- ConflictRevs = [{Start1, RevId1} || {_, {Start1, [RevId1|_]}} <- ConflictRevTuples],
- DeletedConflictRevs = [{Start1, RevId1} || {_, {Start1, [RevId1|_]}} <- DeletedConflictRevTuples],
- DocInfo = #doc_info{
- id=Id,
- update_seq=Seq,
- rev = {Start, RevId},
- summary_pointer = SummaryPointer,
- conflict_revs = ConflictRevs,
- deleted_conflict_revs = DeletedConflictRevs,
- deleted = IsDeleted},
- {DocInfo, Path}.
+max_seq([], Max) ->
+ Max;
+max_seq([#rev_info{seq=Seq}|Rest], Max) ->
+ max_seq(Rest, if Max > Seq -> Max; true -> Seq end).
+
+to_doc_info_path(#full_doc_info{id=Id,rev_tree=Tree}) ->
+ RevInfosAndPath =
+ [{#rev_info{deleted=Del,body_sp=Bp,seq=Seq,rev={Pos,RevId}}, Path} ||
+ {{Del, Bp, Seq},{Pos, [RevId|_]}=Path} <-
+ couch_key_tree:get_all_leafs(Tree)],
+ SortedRevInfosAndPath = lists:sort(
+ fun({#rev_info{deleted=DeletedA,rev=RevA}, _PathA},
+ {#rev_info{deleted=DeletedB,rev=RevB}, _PathB}) ->
+ % sort descending by {not deleted, rev}
+ {not DeletedA, RevA} > {not DeletedB, RevB}
+ end, RevInfosAndPath),
+ [{_RevInfo, WinPath}|_] = SortedRevInfosAndPath,
+ RevInfos = [RevInfo || {RevInfo, _Path} <- SortedRevInfosAndPath],
+ {#doc_info{id=Id, high_seq=max_seq(RevInfos, 0), revs=RevInfos}, WinPath}.
+
+
+
bin_foldl(Bin, Fun, Acc) when is_binary(Bin) ->
case Fun(Bin, Acc) of