diff options
author | Christophe Romain <christophe.romain@process-one.net> | 2017-11-13 20:13:31 +0300 |
---|---|---|
committer | Christophe Romain <christophe.romain@process-one.net> | 2017-11-13 20:13:31 +0300 |
commit | 474536817e0983ddcbfa22db88bd62feb40f2055 (patch) | |
tree | 31e70a658ee5aac6c07ad2bf7b8d13b656f5b763 /src/nodetree_tree.erl | |
parent | daed6a05a60dd6da96936a3a0b900425d3229a72 (diff) |
Implement parentnodes seek for hometree (#1921)
Diffstat (limited to 'src/nodetree_tree.erl')
-rw-r--r-- | src/nodetree_tree.erl | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/src/nodetree_tree.erl b/src/nodetree_tree.erl index f87582c9f..317240366 100644 --- a/src/nodetree_tree.erl +++ b/src/nodetree_tree.erl @@ -86,15 +86,26 @@ get_nodes(Host, _From) -> get_nodes(Host) -> mnesia:match_object(#pubsub_node{nodeid = {Host, '_'}, _ = '_'}). -get_parentnodes(_Host, _Node, _From) -> - []. +get_parentnodes(Host, Node, _From) -> + case catch mnesia:read({pubsub_node, {Host, Node}}) of + [Record] when is_record(Record, pubsub_node) -> + Record#pubsub_node.parents; + _ -> + [] + end. -%% @doc <p>Default node tree does not handle parents, return a list -%% containing just this node.</p> get_parentnodes_tree(Host, Node, _From) -> + get_parentnodes_tree(Host, Node, 0, []). +get_parentnodes_tree(Host, Node, Level, Acc) -> case catch mnesia:read({pubsub_node, {Host, Node}}) of - [Record] when is_record(Record, pubsub_node) -> [{0, [Record]}]; - _ -> [] + [Record] when is_record(Record, pubsub_node) -> + Tree = [{Level, [Record]}|Acc], + case Record#pubsub_node.parents of + [Parent] -> get_parentnodes_tree(Host, Parent, Level+1, Tree); + _ -> Tree + end; + _ -> + Acc end. get_subnodes(Host, Node, _From) -> |