mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-24 16:23:40 +01:00
Normalize pubsub max_items
node options on read
Older version used infinity value, for what never version use max, let's always return max in that case.
This commit is contained in:
parent
08a78a1654
commit
52e7c166fc
@ -73,13 +73,13 @@ get_node(Host, Node, _From) ->
|
|||||||
|
|
||||||
get_node(Host, Node) ->
|
get_node(Host, Node) ->
|
||||||
case mnesia:read({pubsub_node, {Host, Node}}) of
|
case mnesia:read({pubsub_node, {Host, Node}}) of
|
||||||
[Record] when is_record(Record, pubsub_node) -> Record;
|
[#pubsub_node{} = Record] -> fixup_node(Record);
|
||||||
_ -> {error, xmpp:err_item_not_found(?T("Node not found"), ejabberd_option:language())}
|
_ -> {error, xmpp:err_item_not_found(?T("Node not found"), ejabberd_option:language())}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
get_node(Nidx) ->
|
get_node(Nidx) ->
|
||||||
case mnesia:index_read(pubsub_node, Nidx, #pubsub_node.id) of
|
case mnesia:index_read(pubsub_node, Nidx, #pubsub_node.id) of
|
||||||
[Record] when is_record(Record, pubsub_node) -> Record;
|
[#pubsub_node{} = Record] -> fixup_node(Record);
|
||||||
_ -> {error, xmpp:err_item_not_found(?T("Node not found"), ejabberd_option:language())}
|
_ -> {error, xmpp:err_item_not_found(?T("Node not found"), ejabberd_option:language())}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
@ -87,7 +87,8 @@ get_nodes(Host) ->
|
|||||||
get_nodes(Host, infinity).
|
get_nodes(Host, infinity).
|
||||||
|
|
||||||
get_nodes(Host, infinity) ->
|
get_nodes(Host, infinity) ->
|
||||||
mnesia:match_object(#pubsub_node{nodeid = {Host, '_'}, _ = '_'});
|
Nodes = mnesia:match_object(#pubsub_node{nodeid = {Host, '_'}, _ = '_'}),
|
||||||
|
[fixup_node(N) || N <- Nodes];
|
||||||
get_nodes(Host, Limit) ->
|
get_nodes(Host, Limit) ->
|
||||||
case mnesia:select(
|
case mnesia:select(
|
||||||
pubsub_node,
|
pubsub_node,
|
||||||
@ -96,16 +97,18 @@ get_nodes(Host, Limit) ->
|
|||||||
Node
|
Node
|
||||||
end), Limit, read) of
|
end), Limit, read) of
|
||||||
'$end_of_table' -> [];
|
'$end_of_table' -> [];
|
||||||
{Nodes, _} -> Nodes
|
{Nodes, _} -> [fixup_node(N) || N <- Nodes]
|
||||||
end.
|
end.
|
||||||
|
|
||||||
get_all_nodes({_U, _S, _R} = Owner) ->
|
get_all_nodes({_U, _S, _R} = Owner) ->
|
||||||
Host = jid:tolower(jid:remove_resource(Owner)),
|
Host = jid:tolower(jid:remove_resource(Owner)),
|
||||||
mnesia:match_object(#pubsub_node{nodeid = {Host, '_'}, _ = '_'});
|
Nodes = mnesia:match_object(#pubsub_node{nodeid = {Host, '_'}, _ = '_'}),
|
||||||
|
[fixup_node(N) || N <- Nodes];
|
||||||
get_all_nodes(Host) ->
|
get_all_nodes(Host) ->
|
||||||
mnesia:match_object(#pubsub_node{nodeid = {Host, '_'}, _ = '_'})
|
Nodes = mnesia:match_object(#pubsub_node{nodeid = {Host, '_'}, _ = '_'})
|
||||||
++ mnesia:match_object(#pubsub_node{nodeid = {{'_', Host, '_'}, '_'},
|
++ mnesia:match_object(#pubsub_node{nodeid = {{'_', Host, '_'}, '_'},
|
||||||
_ = '_'}).
|
_ = '_'}),
|
||||||
|
[fixup_node(N) || N <- Nodes].
|
||||||
|
|
||||||
get_parentnodes(Host, Node, _From) ->
|
get_parentnodes(Host, Node, _From) ->
|
||||||
case catch mnesia:read({pubsub_node, {Host, Node}}) of
|
case catch mnesia:read({pubsub_node, {Host, Node}}) of
|
||||||
@ -119,7 +122,8 @@ get_parentnodes_tree(Host, Node, _From) ->
|
|||||||
get_parentnodes_tree(Host, Node, 0, []).
|
get_parentnodes_tree(Host, Node, 0, []).
|
||||||
get_parentnodes_tree(Host, Node, Level, Acc) ->
|
get_parentnodes_tree(Host, Node, Level, Acc) ->
|
||||||
case catch mnesia:read({pubsub_node, {Host, Node}}) of
|
case catch mnesia:read({pubsub_node, {Host, Node}}) of
|
||||||
[Record] when is_record(Record, pubsub_node) ->
|
[#pubsub_node{} = Record0] ->
|
||||||
|
Record = fixup_node(Record0),
|
||||||
Tree = [{Level, [Record]}|Acc],
|
Tree = [{Level, [Record]}|Acc],
|
||||||
case Record#pubsub_node.parents of
|
case Record#pubsub_node.parents of
|
||||||
[Parent] -> get_parentnodes_tree(Host, Parent, Level+1, Tree);
|
[Parent] -> get_parentnodes_tree(Host, Parent, Level+1, Tree);
|
||||||
@ -130,7 +134,8 @@ get_parentnodes_tree(Host, Node, Level, Acc) ->
|
|||||||
end.
|
end.
|
||||||
|
|
||||||
get_subnodes(Host, <<>>, infinity) ->
|
get_subnodes(Host, <<>>, infinity) ->
|
||||||
mnesia:match_object(#pubsub_node{nodeid = {Host, '_'}, parents = [], _ = '_'});
|
Nodes = mnesia:match_object(#pubsub_node{nodeid = {Host, '_'}, parents = [], _ = '_'}),
|
||||||
|
[fixup_node(N) || N <- Nodes];
|
||||||
get_subnodes(Host, <<>>, Limit) ->
|
get_subnodes(Host, <<>>, Limit) ->
|
||||||
case mnesia:select(
|
case mnesia:select(
|
||||||
pubsub_node,
|
pubsub_node,
|
||||||
@ -139,10 +144,10 @@ get_subnodes(Host, <<>>, Limit) ->
|
|||||||
Node
|
Node
|
||||||
end), Limit, read) of
|
end), Limit, read) of
|
||||||
'$end_of_table' -> [];
|
'$end_of_table' -> [];
|
||||||
{Nodes, _} -> Nodes
|
{Nodes, _} -> [fixup_node(N) || N <- Nodes]
|
||||||
end;
|
end;
|
||||||
get_subnodes(Host, Node, infinity) ->
|
get_subnodes(Host, Node, infinity) ->
|
||||||
Q = qlc:q([N
|
Q = qlc:q([fixup_node(N)
|
||||||
|| #pubsub_node{nodeid = {NHost, _},
|
|| #pubsub_node{nodeid = {NHost, _},
|
||||||
parents = Parents} =
|
parents = Parents} =
|
||||||
N
|
N
|
||||||
@ -158,9 +163,12 @@ get_subnodes(Host, Node, Limit) ->
|
|||||||
end), Limit, read) of
|
end), Limit, read) of
|
||||||
'$end_of_table' -> [];
|
'$end_of_table' -> [];
|
||||||
{Nodes, _} ->
|
{Nodes, _} ->
|
||||||
lists:filter(
|
lists:filtermap(
|
||||||
fun(#pubsub_node{parents = Parents}) ->
|
fun(#pubsub_node{parents = Parents} = N2) ->
|
||||||
lists:member(Node, Parents)
|
case lists:member(Node, Parents) of
|
||||||
|
true -> {true, fixup_node(N2)};
|
||||||
|
_ -> false
|
||||||
|
end
|
||||||
end, Nodes)
|
end, Nodes)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
@ -236,3 +244,16 @@ delete_node(Host, Node) ->
|
|||||||
end,
|
end,
|
||||||
Removed),
|
Removed),
|
||||||
Removed.
|
Removed.
|
||||||
|
|
||||||
|
fixup_node(#pubsub_node{options = Options} = Node) ->
|
||||||
|
Res = lists:splitwith(
|
||||||
|
fun({max_items, infinity}) -> true;
|
||||||
|
(_) -> false
|
||||||
|
end, Options),
|
||||||
|
Options2 = case Res of
|
||||||
|
{Before, [_ | After]} ->
|
||||||
|
Before ++ [{max_items, max} | After];
|
||||||
|
{Rest, []} ->
|
||||||
|
Rest
|
||||||
|
end,
|
||||||
|
Node#pubsub_node{options = Options2}.
|
||||||
|
@ -328,7 +328,10 @@ raw_to_node(Host, {Node, Parent, Type, Nidx}) ->
|
|||||||
"where nodeid=%(Nidx)d"))
|
"where nodeid=%(Nidx)d"))
|
||||||
of
|
of
|
||||||
{selected, ROptions} ->
|
{selected, ROptions} ->
|
||||||
DbOpts = lists:map(fun ({Key, Value}) ->
|
DbOpts = lists:map(
|
||||||
|
fun({<<"max_items">>, <<"infinity">>}) ->
|
||||||
|
{max_items, max};
|
||||||
|
({Key, Value}) ->
|
||||||
RKey = misc:binary_to_atom(Key),
|
RKey = misc:binary_to_atom(Key),
|
||||||
Tokens = element(2, erl_scan:string(binary_to_list(<<Value/binary, ".">>))),
|
Tokens = element(2, erl_scan:string(binary_to_list(<<Value/binary, ".">>))),
|
||||||
RValue = element(2, erl_parse:parse_term(Tokens)),
|
RValue = element(2, erl_parse:parse_term(Tokens)),
|
||||||
|
Loading…
Reference in New Issue
Block a user