perf(mgmt): optimize clientid lookup when registry is enabled

This commit is contained in:
Thales Macedo Garitezi 2024-06-27 09:37:57 -03:00
parent 7b7f44b9ac
commit c49900af50
2 changed files with 23 additions and 7 deletions

View File

@ -691,10 +691,21 @@ delete_banned(Who) ->
%%--------------------------------------------------------------------
lookup_running_client(ClientId, FormatFun) ->
lists:append([
lookup_client(Node, {clientid, ClientId}, FormatFun)
|| Node <- emqx:running_nodes()
]).
case emqx_cm_registry:is_enabled() of
false ->
lists:append([
lookup_client(Node, {clientid, ClientId}, FormatFun)
|| Node <- emqx:running_nodes()
]);
true ->
case emqx_cm_registry:lookup_channels(ClientId) of
[ChanPid | _] ->
Node = node(ChanPid),
lookup_client(Node, {clientid, ClientId}, FormatFun);
[] ->
[]
end
end.
%%--------------------------------------------------------------------
%% Internal Functions.

View File

@ -180,9 +180,14 @@ t_lookup_client(_Config) ->
),
?assertEqual([], emqx_mgmt:lookup_client({clientid, <<"notfound">>}, ?FORMATFUN)),
meck:expect(emqx, running_nodes, 0, [node(), 'fake@nonode']),
?assertMatch(
[_ | {error, nodedown}], emqx_mgmt:lookup_client({clientid, <<"client1">>}, ?FORMATFUN)
).
try
emqx:update_config([broker, enable_session_registry], false),
?assertMatch(
[_ | {error, nodedown}], emqx_mgmt:lookup_client({clientid, <<"client1">>}, ?FORMATFUN)
)
after
emqx:update_config([broker, enable_session_registry], true)
end.
t_kickout_client(init, Config) ->
process_flag(trap_exit, true),