diff options
-rw-r--r-- | src/nodetree_tree.erl | 23 | ||||
-rw-r--r-- | src/nodetree_tree_sql.erl | 27 |
2 files changed, 36 insertions, 14 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) -> diff --git a/src/nodetree_tree_sql.erl b/src/nodetree_tree_sql.erl index 0b05a885e..73ab74e8a 100644 --- a/src/nodetree_tree_sql.erl +++ b/src/nodetree_tree_sql.erl @@ -160,15 +160,26 @@ get_nodes(Host) -> [] end. -get_parentnodes(_Host, _Node, _From) -> - []. +get_parentnodes(Host, Node, _From) -> + case get_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) -> - case get_node(Host, Node, From) of - {error, _} -> []; - Record -> [{0, [Record]}] +get_parentnodes_tree(Host, Node, _From) -> + get_parentnodes_tree(Host, Node, 0, []). +get_parentnodes_tree(Host, Node, Level, Acc) -> + case get_node(Host, Node) of + 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) -> |