mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-28 16:34:13 +01:00
Speedup features list when a lot of virtual hosts configured
This commit is contained in:
parent
5183f7724d
commit
99fd621aed
@ -82,7 +82,7 @@ process_iq(From, To, #iq{type = T, lang = Lang, sub_els = [El]} = Packet)
|
|||||||
when T == get; T == set ->
|
when T == get; T == set ->
|
||||||
XMLNS = xmpp:get_ns(El),
|
XMLNS = xmpp:get_ns(El),
|
||||||
Host = To#jid.lserver,
|
Host = To#jid.lserver,
|
||||||
case ets:lookup(?IQTABLE, {XMLNS, Host}) of
|
case ets:lookup(?IQTABLE, {Host, XMLNS}) of
|
||||||
[{_, Module, Function}] ->
|
[{_, Module, Function}] ->
|
||||||
gen_iq_handler:handle(Host, Module, Function, no_queue,
|
gen_iq_handler:handle(Host, Module, Function, no_queue,
|
||||||
From, To, Packet);
|
From, To, Packet);
|
||||||
@ -195,11 +195,12 @@ bounce_resource_packet(From, To, Packet) ->
|
|||||||
|
|
||||||
-spec get_features(binary()) -> [binary()].
|
-spec get_features(binary()) -> [binary()].
|
||||||
get_features(Host) ->
|
get_features(Host) ->
|
||||||
ets:select(
|
get_features(ets:next(?IQTABLE, {Host, <<"">>}), Host, []).
|
||||||
?IQTABLE,
|
|
||||||
ets:fun2ms(fun({{XMLNS, H}, _, _, _}) when H == Host ->
|
get_features({Host, XMLNS}, Host, XMLNSs) ->
|
||||||
XMLNS
|
get_features(ets:next(?IQTABLE, {Host, XMLNS}), Host, [XMLNS|XMLNSs]);
|
||||||
end)).
|
get_features(_, _, XMLNSs) ->
|
||||||
|
XMLNSs.
|
||||||
|
|
||||||
%%====================================================================
|
%%====================================================================
|
||||||
%% gen_server callbacks
|
%% gen_server callbacks
|
||||||
@ -216,7 +217,7 @@ init([]) ->
|
|||||||
100)
|
100)
|
||||||
end,
|
end,
|
||||||
?MYHOSTS),
|
?MYHOSTS),
|
||||||
catch ets:new(?IQTABLE, [named_table, public]),
|
catch ets:new(?IQTABLE, [named_table, public, ordered_set]),
|
||||||
update_table(),
|
update_table(),
|
||||||
ejabberd_mnesia:create(?MODULE, iq_response,
|
ejabberd_mnesia:create(?MODULE, iq_response,
|
||||||
[{ram_copies, [node()]},
|
[{ram_copies, [node()]},
|
||||||
@ -240,22 +241,22 @@ handle_info({route, From, To, Packet}, State) ->
|
|||||||
handle_info({register_iq_handler, Host, XMLNS, Module,
|
handle_info({register_iq_handler, Host, XMLNS, Module,
|
||||||
Function},
|
Function},
|
||||||
State) ->
|
State) ->
|
||||||
ets:insert(?IQTABLE, {{XMLNS, Host}, Module, Function}),
|
ets:insert(?IQTABLE, {{Host, XMLNS}, Module, Function}),
|
||||||
{noreply, State};
|
{noreply, State};
|
||||||
handle_info({register_iq_handler, Host, XMLNS, Module,
|
handle_info({register_iq_handler, Host, XMLNS, Module,
|
||||||
Function, Opts},
|
Function, Opts},
|
||||||
State) ->
|
State) ->
|
||||||
ets:insert(?IQTABLE,
|
ets:insert(?IQTABLE,
|
||||||
{{XMLNS, Host}, Module, Function, Opts}),
|
{{Host, XMLNS}, Module, Function, Opts}),
|
||||||
{noreply, State};
|
{noreply, State};
|
||||||
handle_info({unregister_iq_handler, Host, XMLNS},
|
handle_info({unregister_iq_handler, Host, XMLNS},
|
||||||
State) ->
|
State) ->
|
||||||
case ets:lookup(?IQTABLE, {XMLNS, Host}) of
|
case ets:lookup(?IQTABLE, {Host, XMLNS}) of
|
||||||
[{_, Module, Function, Opts}] ->
|
[{_, Module, Function, Opts}] ->
|
||||||
gen_iq_handler:stop_iq_handler(Module, Function, Opts);
|
gen_iq_handler:stop_iq_handler(Module, Function, Opts);
|
||||||
_ -> ok
|
_ -> ok
|
||||||
end,
|
end,
|
||||||
ets:delete(?IQTABLE, {XMLNS, Host}),
|
ets:delete(?IQTABLE, {Host, XMLNS}),
|
||||||
{noreply, State};
|
{noreply, State};
|
||||||
handle_info({timeout, _TRef, ID}, State) ->
|
handle_info({timeout, _TRef, ID}, State) ->
|
||||||
process_iq_timeout(ID),
|
process_iq_timeout(ID),
|
||||||
|
@ -391,7 +391,7 @@ c2s_handle_info(State, _) ->
|
|||||||
|
|
||||||
init([]) ->
|
init([]) ->
|
||||||
lists:foreach(fun(Mod) -> Mod:init() end, get_sm_backends()),
|
lists:foreach(fun(Mod) -> Mod:init() end, get_sm_backends()),
|
||||||
ets:new(sm_iqtable, [named_table]),
|
ets:new(sm_iqtable, [named_table, public]),
|
||||||
lists:foreach(
|
lists:foreach(
|
||||||
fun(Host) ->
|
fun(Host) ->
|
||||||
ejabberd_hooks:add(c2s_handle_info, Host,
|
ejabberd_hooks:add(c2s_handle_info, Host,
|
||||||
@ -422,22 +422,22 @@ handle_info({route, From, To, Packet}, State) ->
|
|||||||
end,
|
end,
|
||||||
{noreply, State};
|
{noreply, State};
|
||||||
handle_info({register_iq_handler, Host, XMLNS, Module, Function}, State) ->
|
handle_info({register_iq_handler, Host, XMLNS, Module, Function}, State) ->
|
||||||
ets:insert(sm_iqtable, {{XMLNS, Host}, Module, Function}),
|
ets:insert(sm_iqtable, {{Host, XMLNS}, Module, Function}),
|
||||||
{noreply, State};
|
{noreply, State};
|
||||||
handle_info({register_iq_handler, Host, XMLNS, Module,
|
handle_info({register_iq_handler, Host, XMLNS, Module,
|
||||||
Function, Opts},
|
Function, Opts},
|
||||||
State) ->
|
State) ->
|
||||||
ets:insert(sm_iqtable,
|
ets:insert(sm_iqtable,
|
||||||
{{XMLNS, Host}, Module, Function, Opts}),
|
{{Host, XMLNS}, Module, Function, Opts}),
|
||||||
{noreply, State};
|
{noreply, State};
|
||||||
handle_info({unregister_iq_handler, Host, XMLNS},
|
handle_info({unregister_iq_handler, Host, XMLNS},
|
||||||
State) ->
|
State) ->
|
||||||
case ets:lookup(sm_iqtable, {XMLNS, Host}) of
|
case ets:lookup(sm_iqtable, {Host, XMLNS}) of
|
||||||
[{_, Module, Function, Opts}] ->
|
[{_, Module, Function, Opts}] ->
|
||||||
gen_iq_handler:stop_iq_handler(Module, Function, Opts);
|
gen_iq_handler:stop_iq_handler(Module, Function, Opts);
|
||||||
_ -> ok
|
_ -> ok
|
||||||
end,
|
end,
|
||||||
ets:delete(sm_iqtable, {XMLNS, Host}),
|
ets:delete(sm_iqtable, {Host, XMLNS}),
|
||||||
{noreply, State};
|
{noreply, State};
|
||||||
handle_info(_Info, State) -> {noreply, State}.
|
handle_info(_Info, State) -> {noreply, State}.
|
||||||
|
|
||||||
@ -743,7 +743,7 @@ process_iq(From, To, #iq{type = T, lang = Lang, sub_els = [El]} = Packet)
|
|||||||
when T == get; T == set ->
|
when T == get; T == set ->
|
||||||
XMLNS = xmpp:get_ns(El),
|
XMLNS = xmpp:get_ns(El),
|
||||||
Host = To#jid.lserver,
|
Host = To#jid.lserver,
|
||||||
case ets:lookup(sm_iqtable, {XMLNS, Host}) of
|
case ets:lookup(sm_iqtable, {Host, XMLNS}) of
|
||||||
[{_, Module, Function}] ->
|
[{_, Module, Function}] ->
|
||||||
gen_iq_handler:handle(Host, Module, Function, no_queue,
|
gen_iq_handler:handle(Host, Module, Function, no_queue,
|
||||||
From, To, Packet);
|
From, To, Packet);
|
||||||
|
Loading…
Reference in New Issue
Block a user