You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by rn...@apache.org on 2014/08/07 17:38:03 UTC
[41/50] couch commit: updated refs/heads/windsor-merge to 6e60cbe
Add couch_doc:is_deleted/1
This adds a helper function for checking if a \#full_doc_info is
deleted. It's more effecient than checking the first \#rev_info in the
result of couch_doc:to_doc_info/1 because it simply checks if any leaf
is deleted rather than sorting the leaves based on deleted status.
BugzId: 25150
Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch/commit/68a10128
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch/tree/68a10128
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch/diff/68a10128
Branch: refs/heads/windsor-merge
Commit: 68a1012801b59ff3f33eba30fabc96cfefa8bb2b
Parents: 050fea2
Author: Benjamin Bastian <be...@gmail.com>
Authored: Thu Dec 12 13:23:49 2013 -0800
Committer: Robert Newson <rn...@apache.org>
Committed: Wed Aug 6 15:21:37 2014 +0100
----------------------------------------------------------------------
src/couch_doc.erl | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/68a10128/src/couch_doc.erl
----------------------------------------------------------------------
diff --git a/src/couch_doc.erl b/src/couch_doc.erl
index 9263ba3..d82d626 100644
--- a/src/couch_doc.erl
+++ b/src/couch_doc.erl
@@ -22,6 +22,7 @@
-export([to_path/1]).
-export([mp_parse_doc/2]).
-export([with_ejson_body/1]).
+-export([is_deleted/1]).
-include_lib("couch/include/couch_db.hrl").
@@ -367,6 +368,23 @@ to_doc_info_path(#full_doc_info{id=Id,rev_tree=Tree,update_seq=FDISeq}) ->
{#doc_info{id=Id, high_seq=max_seq(Tree, FDISeq), revs=RevInfos}, WinPath}.
+is_deleted(#full_doc_info{rev_tree=Tree}) ->
+ is_deleted(Tree);
+is_deleted(Tree) ->
+ Leafs = couch_key_tree:get_all_leafs(Tree),
+ try
+ lists:foldl(fun
+ ({#leaf{deleted=false},_}, _) ->
+ throw(not_deleted);
+ ({#doc{deleted=false},_}, _) ->
+ throw(not_deleted);
+ (_, Acc) ->
+ Acc
+ end, nil, Leafs),
+ true
+ catch throw:not_deleted ->
+ false
+ end.
att_foldl(#att{data=Bin}, Fun, Acc) when is_binary(Bin) ->