25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-22 16:20:52 +01:00

Implement parentnodes seek for hometree (#1921)

This commit is contained in:
Christophe Romain 2017-11-13 18:13:31 +01:00
parent daed6a05a6
commit 474536817e
2 changed files with 38 additions and 16 deletions

View File

@ -86,15 +86,26 @@ get_nodes(Host, _From) ->
get_nodes(Host) ->
mnesia:match_object(#pubsub_node{nodeid = {Host, '_'}, _ = '_'}).
get_parentnodes(_Host, _Node, _From) ->
[].
%% @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(Host, Node, _From) ->
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) ->
Record#pubsub_node.parents;
_ ->
[]
end.
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) ->
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) ->

View File

@ -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) ->