24
1
mirror of https://github.com/processone/ejabberd.git synced 2024-06-14 22:00:16 +02:00

Avoid useless calls on simples subscriptions (#1313)

This commit is contained in:
Christophe Romain 2017-06-29 15:24:18 +02:00
parent fcf672c50e
commit 800965a957

View File

@ -3009,60 +3009,61 @@ c2s_handle_info(C2SState, _) ->
subscribed_nodes_by_jid(NotifyType, SubsByDepth) -> subscribed_nodes_by_jid(NotifyType, SubsByDepth) ->
NodesToDeliver = fun (Depth, Node, Subs, Acc) -> NodesToDeliver = fun (Depth, Node, Subs, Acc) ->
NodeName = case Node#pubsub_node.nodeid of NodeName = case Node#pubsub_node.nodeid of
{_, N} -> N; {_, N} -> N;
Other -> Other Other -> Other
end, end,
NodeOptions = Node#pubsub_node.options, NodeOptions = Node#pubsub_node.options,
lists:foldl(fun({LJID, SubID, SubOptions}, {JIDs, Recipients}) -> lists:foldl(fun({LJID, SubID, SubOptions}, {JIDs, Recipients}) ->
case is_to_deliver(LJID, NotifyType, Depth, NodeOptions, SubOptions) of case is_to_deliver(LJID, NotifyType, Depth, NodeOptions, SubOptions) of
true -> true ->
case state_can_deliver(LJID, SubOptions) of case state_can_deliver(LJID, SubOptions) of
[] -> {JIDs, Recipients}; [] -> {JIDs, Recipients};
JIDsToDeliver -> [LJID] -> {JIDs, [{LJID, NodeName, [SubID]} | Recipients]};
lists:foldl( JIDsToDeliver ->
fun(JIDToDeliver, {JIDsAcc, RecipientsAcc}) -> lists:foldl(
case lists:member(JIDToDeliver, JIDs) of fun(JIDToDeliver, {JIDsAcc, RecipientsAcc}) ->
%% check if the JIDs co-accumulator contains the Subscription Jid, case lists:member(JIDToDeliver, JIDs) of
false -> %% check if the JIDs co-accumulator contains the Subscription Jid,
%% - if not, false ->
%% - add the Jid to JIDs list co-accumulator ; %% - if not,
%% - create a tuple of the Jid, Nidx, and SubID (as list), %% - add the Jid to JIDs list co-accumulator ;
%% and add the tuple to the Recipients list co-accumulator %% - create a tuple of the Jid, Nidx, and SubID (as list),
{[JIDToDeliver | JIDsAcc], %% and add the tuple to the Recipients list co-accumulator
[{JIDToDeliver, NodeName, [SubID]} {[JIDToDeliver | JIDsAcc],
| RecipientsAcc]}; [{JIDToDeliver, NodeName, [SubID]}
true -> | RecipientsAcc]};
%% - if the JIDs co-accumulator contains the Jid true ->
%% get the tuple containing the Jid from the Recipient list co-accumulator %% - if the JIDs co-accumulator contains the Jid
{_, {JIDToDeliver, NodeName1, SubIDs}} = %% get the tuple containing the Jid from the Recipient list co-accumulator
lists:keysearch(JIDToDeliver, 1, RecipientsAcc), {_, {JIDToDeliver, NodeName1, SubIDs}} =
%% delete the tuple from the Recipients list lists:keysearch(JIDToDeliver, 1, RecipientsAcc),
% v1 : Recipients1 = lists:keydelete(LJID, 1, Recipients), %% delete the tuple from the Recipients list
% v2 : Recipients1 = lists:keyreplace(LJID, 1, Recipients, {LJID, Nidx1, [SubID | SubIDs]}), % v1 : Recipients1 = lists:keydelete(LJID, 1, Recipients),
%% add the SubID to the SubIDs list in the tuple, % v2 : Recipients1 = lists:keyreplace(LJID, 1, Recipients, {LJID, Nidx1, [SubID | SubIDs]}),
%% and add the tuple back to the Recipients list co-accumulator %% add the SubID to the SubIDs list in the tuple,
% v1.1 : {JIDs, lists:append(Recipients1, [{LJID, Nidx1, lists:append(SubIDs, [SubID])}])} %% and add the tuple back to the Recipients list co-accumulator
% v1.2 : {JIDs, [{LJID, Nidx1, [SubID | SubIDs]} | Recipients1]} % v1.1 : {JIDs, lists:append(Recipients1, [{LJID, Nidx1, lists:append(SubIDs, [SubID])}])}
% v2: {JIDs, Recipients1} % v1.2 : {JIDs, [{LJID, Nidx1, [SubID | SubIDs]} | Recipients1]}
{JIDsAcc, % v2: {JIDs, Recipients1}
lists:keyreplace(JIDToDeliver, 1, {JIDsAcc,
RecipientsAcc, lists:keyreplace(JIDToDeliver, 1,
{JIDToDeliver, NodeName1, RecipientsAcc,
[SubID | SubIDs]})} {JIDToDeliver, NodeName1,
end [SubID | SubIDs]})}
end, {JIDs, Recipients}, JIDsToDeliver) end
end; end, {JIDs, Recipients}, JIDsToDeliver)
false -> end;
{JIDs, Recipients} false ->
end {JIDs, Recipients}
end, Acc, Subs) end
end, end, Acc, Subs)
end,
DepthsToDeliver = fun({Depth, SubsByNode}, Acc1) -> DepthsToDeliver = fun({Depth, SubsByNode}, Acc1) ->
lists:foldl(fun({Node, Subs}, Acc2) -> lists:foldl(fun({Node, Subs}, Acc2) ->
NodesToDeliver(Depth, Node, Subs, Acc2) NodesToDeliver(Depth, Node, Subs, Acc2)
end, Acc1, SubsByNode) end, Acc1, SubsByNode)
end, end,
{_, JIDSubs} = lists:foldl(DepthsToDeliver, {[], []}, SubsByDepth), {_, JIDSubs} = lists:foldl(DepthsToDeliver, {[], []}, SubsByDepth),
JIDSubs. JIDSubs.