mirror of
https://github.com/processone/ejabberd.git
synced 2024-10-31 15:21:38 +01:00
put cleaning code to pubsub_debug
This commit is contained in:
parent
e8d008c392
commit
e3085a4d48
@ -1,57 +0,0 @@
|
|||||||
-module(pubsub_clean).
|
|
||||||
|
|
||||||
-define(TIMEOUT, 1000 * 600).
|
|
||||||
|
|
||||||
-export([start/0, loop/0, purge/0, offline/1]).
|
|
||||||
|
|
||||||
start() ->
|
|
||||||
Pid = spawn(?MODULE, loop, []),
|
|
||||||
register(pubsub_clean, Pid),
|
|
||||||
Pid.
|
|
||||||
|
|
||||||
loop() ->
|
|
||||||
receive purge -> purge() after ?TIMEOUT -> purge() end,
|
|
||||||
loop().
|
|
||||||
|
|
||||||
purge() ->
|
|
||||||
Sessions = lists:sum([mnesia:table_info(session, size)
|
|
||||||
| [rpc:call(N, mnesia, table_info, [session, size])
|
|
||||||
|| N <- nodes()]]),
|
|
||||||
Subscriptions = mnesia:table_info(pubsub_state, size),
|
|
||||||
if Subscriptions > Sessions + 500 ->
|
|
||||||
lists:foreach(fun (K) ->
|
|
||||||
[N] = mnesia:dirty_read({pubsub_node, K}),
|
|
||||||
I = element(3, N),
|
|
||||||
lists:foreach(fun (JID) ->
|
|
||||||
case
|
|
||||||
mnesia:dirty_read({pubsub_state,
|
|
||||||
{JID,
|
|
||||||
I}})
|
|
||||||
of
|
|
||||||
[{pubsub_state, K, _,
|
|
||||||
_, _,
|
|
||||||
[{subscribed,
|
|
||||||
S}]}] ->
|
|
||||||
mnesia:dirty_delete({pubsub_subscription,
|
|
||||||
S});
|
|
||||||
_ -> ok
|
|
||||||
end,
|
|
||||||
mnesia:dirty_delete({pubsub_state,
|
|
||||||
{JID,
|
|
||||||
I}})
|
|
||||||
end,
|
|
||||||
offline(pubsub_debug:subscribed(I)))
|
|
||||||
end,
|
|
||||||
mnesia:dirty_all_keys(pubsub_node));
|
|
||||||
true -> ok
|
|
||||||
end.
|
|
||||||
|
|
||||||
offline(Jids) ->
|
|
||||||
lists:filter(fun ({U, S, <<"">>}) ->
|
|
||||||
ejabberd_sm:get_user_resources(U, S) == [];
|
|
||||||
({U, S, R}) ->
|
|
||||||
not
|
|
||||||
lists:member(R, ejabberd_sm:get_user_resources(U, S))
|
|
||||||
end,
|
|
||||||
Jids).%%ejabberd_cluster:get_node({LUser, LServer})
|
|
||||||
|
|
@ -107,6 +107,16 @@ subscribed(NodeId) ->
|
|||||||
|| S <- states(NodeId),
|
|| S <- states(NodeId),
|
||||||
S#pubsub_state.subscriptions =/= []].
|
S#pubsub_state.subscriptions =/= []].
|
||||||
|
|
||||||
|
offline_subscribers(NodeId) ->
|
||||||
|
lists:filter(fun ({U, S, <<"">>}) ->
|
||||||
|
ejabberd_sm:get_user_resources(U, S) == [];
|
||||||
|
({U, S, R}) ->
|
||||||
|
not
|
||||||
|
lists:member(R, ejabberd_sm:get_user_resources(U, S))
|
||||||
|
end,
|
||||||
|
subscribed(NodeId)).
|
||||||
|
|
||||||
|
|
||||||
owners(NodeId) ->
|
owners(NodeId) ->
|
||||||
[stateid(S)
|
[stateid(S)
|
||||||
|| S <- states(NodeId),
|
|| S <- states(NodeId),
|
||||||
@ -254,3 +264,20 @@ pep_subscriptions(LUser, LServer, LResource) ->
|
|||||||
end;
|
end;
|
||||||
_ -> []
|
_ -> []
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
purge_offline_subscriptions() ->
|
||||||
|
lists:foreach(fun (K) ->
|
||||||
|
[N] = mnesia:dirty_read({pubsub_node, K}),
|
||||||
|
I = element(3, N),
|
||||||
|
lists:foreach(fun (JID) ->
|
||||||
|
case mnesia:dirty_read({pubsub_state, {JID, I}}) of
|
||||||
|
[{pubsub_state, K, _, _, _, [{subscribed, S}]}] ->
|
||||||
|
mnesia:dirty_delete({pubsub_subscription, S});
|
||||||
|
_ ->
|
||||||
|
ok
|
||||||
|
end,
|
||||||
|
mnesia:dirty_delete({pubsub_state, {JID, I}})
|
||||||
|
end,
|
||||||
|
offline_subscribers(I))
|
||||||
|
end,
|
||||||
|
mnesia:dirty_all_keys(pubsub_node)).
|
||||||
|
Loading…
Reference in New Issue
Block a user