summaryrefslogtreecommitdiff
path: root/src/mod_pubsub.erl
diff options
context:
space:
mode:
authorChristophe Romain <christophe.romain@process-one.net>2017-06-29 15:24:18 +0200
committerChristophe Romain <christophe.romain@process-one.net>2017-06-29 15:24:18 +0200
commit800965a957ccaa3832edd36c5b277b1d9ecc9d80 (patch)
tree53a083c84f2a6b7a4d52af5c3ee67337ae3658d8 /src/mod_pubsub.erl
parentAdd allow_local_users to mod_block_strangers (#1804, #1809) (diff)
Avoid useless calls on simples subscriptions (#1313)
Diffstat (limited to 'src/mod_pubsub.erl')
-rw-r--r--src/mod_pubsub.erl107
1 files changed, 54 insertions, 53 deletions
diff --git a/src/mod_pubsub.erl b/src/mod_pubsub.erl
index 91d2f928..1a620cb6 100644
--- a/src/mod_pubsub.erl
+++ b/src/mod_pubsub.erl
@@ -3009,60 +3009,61 @@ c2s_handle_info(C2SState, _) ->
subscribed_nodes_by_jid(NotifyType, SubsByDepth) ->
NodesToDeliver = fun (Depth, Node, Subs, Acc) ->
- NodeName = case Node#pubsub_node.nodeid of
- {_, N} -> N;
- Other -> Other
- end,
- NodeOptions = Node#pubsub_node.options,
- lists:foldl(fun({LJID, SubID, SubOptions}, {JIDs, Recipients}) ->
- case is_to_deliver(LJID, NotifyType, Depth, NodeOptions, SubOptions) of
- true ->
- case state_can_deliver(LJID, SubOptions) of
- [] -> {JIDs, Recipients};
- JIDsToDeliver ->
- lists:foldl(
- fun(JIDToDeliver, {JIDsAcc, RecipientsAcc}) ->
- case lists:member(JIDToDeliver, JIDs) of
- %% check if the JIDs co-accumulator contains the Subscription Jid,
- false ->
- %% - if not,
- %% - add the Jid to JIDs list co-accumulator ;
- %% - create a tuple of the Jid, Nidx, and SubID (as list),
- %% and add the tuple to the Recipients list co-accumulator
- {[JIDToDeliver | JIDsAcc],
- [{JIDToDeliver, NodeName, [SubID]}
- | RecipientsAcc]};
- true ->
- %% - if the JIDs co-accumulator contains the Jid
- %% get the tuple containing the Jid from the Recipient list co-accumulator
- {_, {JIDToDeliver, NodeName1, SubIDs}} =
- lists:keysearch(JIDToDeliver, 1, RecipientsAcc),
- %% delete the tuple from the Recipients list
- % v1 : Recipients1 = lists:keydelete(LJID, 1, Recipients),
- % v2 : Recipients1 = lists:keyreplace(LJID, 1, Recipients, {LJID, Nidx1, [SubID | SubIDs]}),
- %% add the SubID to the SubIDs list in the tuple,
- %% and add the tuple back to the Recipients list co-accumulator
- % v1.1 : {JIDs, lists:append(Recipients1, [{LJID, Nidx1, lists:append(SubIDs, [SubID])}])}
- % v1.2 : {JIDs, [{LJID, Nidx1, [SubID | SubIDs]} | Recipients1]}
- % v2: {JIDs, Recipients1}
- {JIDsAcc,
- lists:keyreplace(JIDToDeliver, 1,
- RecipientsAcc,
- {JIDToDeliver, NodeName1,
- [SubID | SubIDs]})}
- end
- end, {JIDs, Recipients}, JIDsToDeliver)
- end;
- false ->
- {JIDs, Recipients}
- end
- end, Acc, Subs)
- end,
+ NodeName = case Node#pubsub_node.nodeid of
+ {_, N} -> N;
+ Other -> Other
+ end,
+ NodeOptions = Node#pubsub_node.options,
+ lists:foldl(fun({LJID, SubID, SubOptions}, {JIDs, Recipients}) ->
+ case is_to_deliver(LJID, NotifyType, Depth, NodeOptions, SubOptions) of
+ true ->
+ case state_can_deliver(LJID, SubOptions) of
+ [] -> {JIDs, Recipients};
+ [LJID] -> {JIDs, [{LJID, NodeName, [SubID]} | Recipients]};
+ JIDsToDeliver ->
+ lists:foldl(
+ fun(JIDToDeliver, {JIDsAcc, RecipientsAcc}) ->
+ case lists:member(JIDToDeliver, JIDs) of
+ %% check if the JIDs co-accumulator contains the Subscription Jid,
+ false ->
+ %% - if not,
+ %% - add the Jid to JIDs list co-accumulator ;
+ %% - create a tuple of the Jid, Nidx, and SubID (as list),
+ %% and add the tuple to the Recipients list co-accumulator
+ {[JIDToDeliver | JIDsAcc],
+ [{JIDToDeliver, NodeName, [SubID]}
+ | RecipientsAcc]};
+ true ->
+ %% - if the JIDs co-accumulator contains the Jid
+ %% get the tuple containing the Jid from the Recipient list co-accumulator
+ {_, {JIDToDeliver, NodeName1, SubIDs}} =
+ lists:keysearch(JIDToDeliver, 1, RecipientsAcc),
+ %% delete the tuple from the Recipients list
+ % v1 : Recipients1 = lists:keydelete(LJID, 1, Recipients),
+ % v2 : Recipients1 = lists:keyreplace(LJID, 1, Recipients, {LJID, Nidx1, [SubID | SubIDs]}),
+ %% add the SubID to the SubIDs list in the tuple,
+ %% and add the tuple back to the Recipients list co-accumulator
+ % v1.1 : {JIDs, lists:append(Recipients1, [{LJID, Nidx1, lists:append(SubIDs, [SubID])}])}
+ % v1.2 : {JIDs, [{LJID, Nidx1, [SubID | SubIDs]} | Recipients1]}
+ % v2: {JIDs, Recipients1}
+ {JIDsAcc,
+ lists:keyreplace(JIDToDeliver, 1,
+ RecipientsAcc,
+ {JIDToDeliver, NodeName1,
+ [SubID | SubIDs]})}
+ end
+ end, {JIDs, Recipients}, JIDsToDeliver)
+ end;
+ false ->
+ {JIDs, Recipients}
+ end
+ end, Acc, Subs)
+ end,
DepthsToDeliver = fun({Depth, SubsByNode}, Acc1) ->
- lists:foldl(fun({Node, Subs}, Acc2) ->
- NodesToDeliver(Depth, Node, Subs, Acc2)
- end, Acc1, SubsByNode)
- end,
+ lists:foldl(fun({Node, Subs}, Acc2) ->
+ NodesToDeliver(Depth, Node, Subs, Acc2)
+ end, Acc1, SubsByNode)
+ end,
{_, JIDSubs} = lists:foldl(DepthsToDeliver, {[], []}, SubsByDepth),
JIDSubs.