fix(mgmt): make the format function clearer

Co-authored-by: Zaiming Shi <zmstone@gmail.com>
This commit is contained in:
JianBo He 2021-02-13 10:09:14 +08:00
parent fcbf2539bc
commit 56a75d0d47
2 changed files with 9 additions and 7 deletions

View File

@ -302,14 +302,20 @@ lookup_client({username, Username}, FormatFun) ->
lists:append([lookup_client(Node, {username, Username}, FormatFun) || Node <- ekka_mnesia:running_nodes()]). lists:append([lookup_client(Node, {username, Username}, FormatFun) || Node <- ekka_mnesia:running_nodes()]).
lookup_client(Node, {clientid, ClientId}, {M,F}) when Node =:= node() -> lookup_client(Node, {clientid, ClientId}, {M,F}) when Node =:= node() ->
lists:map(fun(E) -> M:F(E) end, ets:lookup(emqx_channel, ClientId)); lists:append(lists:map(
fun(Key) ->
lists:map(fun M:F/1, ets:lookup(emqx_channel_info, Key))
end, ets:lookup(emqx_channel, ClientId)));
lookup_client(Node, {clientid, ClientId}, FormatFun) -> lookup_client(Node, {clientid, ClientId}, FormatFun) ->
rpc_call(Node, lookup_client, [Node, {clientid, ClientId}, FormatFun]); rpc_call(Node, lookup_client, [Node, {clientid, ClientId}, FormatFun]);
lookup_client(Node, {username, Username}, {M,F}) when Node =:= node() -> lookup_client(Node, {username, Username}, {M,F}) when Node =:= node() ->
MatchSpec = [{{'$1', #{clientinfo => #{username => '$2'}}, '_'}, [{'=:=','$2', Username}], ['$1']}], MatchSpec = [{ {'_', #{clientinfo => #{username => '$1'}}, '_'}
lists:map(fun(E) -> M:F(E) end, ets:select(emqx_channel_info, MatchSpec)); , [{'=:=','$1', Username}]
, ['$_']
}],
lists:map(fun M:F/1, ets:select(emqx_channel_info, MatchSpec));
lookup_client(Node, {username, Username}, FormatFun) -> lookup_client(Node, {username, Username}, FormatFun) ->
rpc_call(Node, lookup_client, [Node, {username, Username}, FormatFun]). rpc_call(Node, lookup_client, [Node, {username, Username}, FormatFun]).

View File

@ -249,10 +249,6 @@ parse_ratelimit_str(S) ->
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% Format %% Format
format_channel_info(Key = {_ClientId, _Pid}) ->
[E] = ets:lookup(emqx_channel_info, Key),
format_channel_info(E);
format_channel_info({_Key, Info, Stats0}) -> format_channel_info({_Key, Info, Stats0}) ->
Stats = maps:from_list(Stats0), Stats = maps:from_list(Stats0),
ClientInfo = maps:get(clientinfo, Info, #{}), ClientInfo = maps:get(clientinfo, Info, #{}),