mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-22 16:20:52 +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 ->
|
||||
XMLNS = xmpp:get_ns(El),
|
||||
Host = To#jid.lserver,
|
||||
case ets:lookup(?IQTABLE, {XMLNS, Host}) of
|
||||
case ets:lookup(?IQTABLE, {Host, XMLNS}) of
|
||||
[{_, Module, Function}] ->
|
||||
gen_iq_handler:handle(Host, Module, Function, no_queue,
|
||||
From, To, Packet);
|
||||
@ -195,11 +195,12 @@ bounce_resource_packet(From, To, Packet) ->
|
||||
|
||||
-spec get_features(binary()) -> [binary()].
|
||||
get_features(Host) ->
|
||||
ets:select(
|
||||
?IQTABLE,
|
||||
ets:fun2ms(fun({{XMLNS, H}, _, _, _}) when H == Host ->
|
||||
XMLNS
|
||||
end)).
|
||||
get_features(ets:next(?IQTABLE, {Host, <<"">>}), Host, []).
|
||||
|
||||
get_features({Host, XMLNS}, Host, XMLNSs) ->
|
||||
get_features(ets:next(?IQTABLE, {Host, XMLNS}), Host, [XMLNS|XMLNSs]);
|
||||
get_features(_, _, XMLNSs) ->
|
||||
XMLNSs.
|
||||
|
||||
%%====================================================================
|
||||
%% gen_server callbacks
|
||||
@ -216,7 +217,7 @@ init([]) ->
|
||||
100)
|
||||
end,
|
||||
?MYHOSTS),
|
||||
catch ets:new(?IQTABLE, [named_table, public]),
|
||||
catch ets:new(?IQTABLE, [named_table, public, ordered_set]),
|
||||
update_table(),
|
||||
ejabberd_mnesia:create(?MODULE, iq_response,
|
||||
[{ram_copies, [node()]},
|
||||
@ -240,22 +241,22 @@ handle_info({route, From, To, Packet}, State) ->
|
||||
handle_info({register_iq_handler, Host, XMLNS, Module,
|
||||
Function},
|
||||
State) ->
|
||||
ets:insert(?IQTABLE, {{XMLNS, Host}, Module, Function}),
|
||||
ets:insert(?IQTABLE, {{Host, XMLNS}, Module, Function}),
|
||||
{noreply, State};
|
||||
handle_info({register_iq_handler, Host, XMLNS, Module,
|
||||
Function, Opts},
|
||||
State) ->
|
||||
ets:insert(?IQTABLE,
|
||||
{{XMLNS, Host}, Module, Function, Opts}),
|
||||
{{Host, XMLNS}, Module, Function, Opts}),
|
||||
{noreply, State};
|
||||
handle_info({unregister_iq_handler, Host, XMLNS},
|
||||
State) ->
|
||||
case ets:lookup(?IQTABLE, {XMLNS, Host}) of
|
||||
case ets:lookup(?IQTABLE, {Host, XMLNS}) of
|
||||
[{_, Module, Function, Opts}] ->
|
||||
gen_iq_handler:stop_iq_handler(Module, Function, Opts);
|
||||
_ -> ok
|
||||
end,
|
||||
ets:delete(?IQTABLE, {XMLNS, Host}),
|
||||
ets:delete(?IQTABLE, {Host, XMLNS}),
|
||||
{noreply, State};
|
||||
handle_info({timeout, _TRef, ID}, State) ->
|
||||
process_iq_timeout(ID),
|
||||
|
@ -391,7 +391,7 @@ c2s_handle_info(State, _) ->
|
||||
|
||||
init([]) ->
|
||||
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(
|
||||
fun(Host) ->
|
||||
ejabberd_hooks:add(c2s_handle_info, Host,
|
||||
@ -422,22 +422,22 @@ handle_info({route, From, To, Packet}, State) ->
|
||||
end,
|
||||
{noreply, 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};
|
||||
handle_info({register_iq_handler, Host, XMLNS, Module,
|
||||
Function, Opts},
|
||||
State) ->
|
||||
ets:insert(sm_iqtable,
|
||||
{{XMLNS, Host}, Module, Function, Opts}),
|
||||
{{Host, XMLNS}, Module, Function, Opts}),
|
||||
{noreply, State};
|
||||
handle_info({unregister_iq_handler, Host, XMLNS},
|
||||
State) ->
|
||||
case ets:lookup(sm_iqtable, {XMLNS, Host}) of
|
||||
case ets:lookup(sm_iqtable, {Host, XMLNS}) of
|
||||
[{_, Module, Function, Opts}] ->
|
||||
gen_iq_handler:stop_iq_handler(Module, Function, Opts);
|
||||
_ -> ok
|
||||
end,
|
||||
ets:delete(sm_iqtable, {XMLNS, Host}),
|
||||
ets:delete(sm_iqtable, {Host, XMLNS}),
|
||||
{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 ->
|
||||
XMLNS = xmpp:get_ns(El),
|
||||
Host = To#jid.lserver,
|
||||
case ets:lookup(sm_iqtable, {XMLNS, Host}) of
|
||||
case ets:lookup(sm_iqtable, {Host, XMLNS}) of
|
||||
[{_, Module, Function}] ->
|
||||
gen_iq_handler:handle(Host, Module, Function, no_queue,
|
||||
From, To, Packet);
|
||||
|
Loading…
Reference in New Issue
Block a user