refactor(mgmt_api): `select_table_with_count`.
This commit is contained in:
parent
ea7aa5bc41
commit
3960204ce3
|
@ -196,13 +196,13 @@ extra_sub_props(Props) ->
|
|||
|
||||
query(Tab, {Qs, []}, Continuation, Limit) ->
|
||||
Ms = qs2ms(Qs),
|
||||
emqx_mgmt_api:select_table(Tab, Ms, Continuation, Limit,
|
||||
emqx_mgmt_api:select_table_with_count(Tab, Ms, Continuation, Limit,
|
||||
fun format_channel_info/1);
|
||||
|
||||
query(Tab, {Qs, Fuzzy}, Continuation, Limit) ->
|
||||
Ms = qs2ms(Qs),
|
||||
FuzzyFilterFun = fuzzy_filter_fun(Fuzzy),
|
||||
emqx_mgmt_api:select_table(Tab, {Ms, FuzzyFilterFun}, Continuation, Limit,
|
||||
emqx_mgmt_api:select_table_with_count(Tab, {Ms, FuzzyFilterFun}, Continuation, Limit,
|
||||
fun format_channel_info/1).
|
||||
|
||||
qs2ms(Qs) ->
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
%% first_next query APIs
|
||||
-export([ node_query/5
|
||||
, cluster_query/4
|
||||
, select_table/5
|
||||
, select_table_with_count/5
|
||||
]).
|
||||
|
||||
-export([do_query/6]).
|
||||
|
@ -196,36 +196,38 @@ rpc_call(Node, M, F, A, T) ->
|
|||
%% Table Select
|
||||
%%--------------------------------------------------------------------
|
||||
|
||||
select_table(Tab, {Ms, FuzzyFilterFun}, ?FRESH_SELECT, Limit, FmtFun)
|
||||
select_table_with_count(Tab, {Ms, FuzzyFilterFun}, ?FRESH_SELECT, Limit, FmtFun)
|
||||
when is_function(FuzzyFilterFun) andalso Limit > 0 ->
|
||||
case ets:select(Tab, Ms, Limit) of
|
||||
'$end_of_table' ->
|
||||
{[], ?FRESH_SELECT};
|
||||
{0, [], ?FRESH_SELECT};
|
||||
{RawResult, NContinuation} ->
|
||||
{lists:map(FmtFun, lists:reverse(FuzzyFilterFun(RawResult))), NContinuation}
|
||||
Rows = FuzzyFilterFun(RawResult),
|
||||
{length(Rows), lists:map(FmtFun, Rows), NContinuation}
|
||||
end;
|
||||
select_table(_Tab, {_Ms, FuzzyFilterFun}, Continuation, _Limit, FmtFun)
|
||||
select_table_with_count(_Tab, {_Ms, FuzzyFilterFun}, Continuation, _Limit, FmtFun)
|
||||
when is_function(FuzzyFilterFun) ->
|
||||
case ets:select(Continuation) of
|
||||
'$end_of_table' ->
|
||||
{[], ?FRESH_SELECT};
|
||||
{0, [], ?FRESH_SELECT};
|
||||
{RawResult, NContinuation} ->
|
||||
{lists:map(FmtFun, lists:reverse(FuzzyFilterFun(RawResult))), NContinuation}
|
||||
Rows = FuzzyFilterFun(RawResult),
|
||||
{length(Rows), lists:map(FmtFun, Rows), NContinuation}
|
||||
end;
|
||||
select_table(Tab, Ms, ?FRESH_SELECT, Limit, FmtFun)
|
||||
select_table_with_count(Tab, Ms, ?FRESH_SELECT, Limit, FmtFun)
|
||||
when Limit > 0 ->
|
||||
case ets:select(Tab, Ms, Limit) of
|
||||
'$end_of_table' ->
|
||||
{[], ?FRESH_SELECT};
|
||||
{0, [], ?FRESH_SELECT};
|
||||
{RawResult, NContinuation} ->
|
||||
{lists:map(FmtFun, lists:reverse(RawResult)), NContinuation}
|
||||
{length(RawResult), lists:map(FmtFun, RawResult), NContinuation}
|
||||
end;
|
||||
select_table(_Tab, _Ms, Continuation, _Limit, FmtFun) ->
|
||||
select_table_with_count(_Tab, _Ms, Continuation, _Limit, FmtFun) ->
|
||||
case ets:select(Continuation) of
|
||||
'$end_of_table' ->
|
||||
{[], ?FRESH_SELECT};
|
||||
{0, [], ?FRESH_SELECT};
|
||||
{RawResult, NContinuation} ->
|
||||
{lists:map(FmtFun, lists:reverse(RawResult)), NContinuation}
|
||||
{length(RawResult), lists:map(FmtFun, RawResult), NContinuation}
|
||||
end.
|
||||
|
||||
%%--------------------------------------------------------------------
|
||||
|
|
|
@ -90,7 +90,7 @@ alarms(delete, _Params) ->
|
|||
|
||||
query(Table, _QsSpec, Continuation, Limit) ->
|
||||
Ms = [{'$1',[],['$1']}],
|
||||
emqx_mgmt_api:select_table(Table, Ms, Continuation, Limit, fun format_alarm/1).
|
||||
emqx_mgmt_api:select_table_with_count(Table, Ms, Continuation, Limit, fun format_alarm/1).
|
||||
|
||||
format_alarm(Alarms) when is_list(Alarms) ->
|
||||
[emqx_alarm:format(Alarm) || Alarm <- Alarms];
|
||||
|
|
|
@ -557,13 +557,13 @@ generate_qs(Qs) ->
|
|||
|
||||
query(Tab, {Qs, []}, Continuation, Limit) ->
|
||||
Ms = qs2ms(Qs),
|
||||
emqx_mgmt_api:select_table(Tab, Ms, Continuation, Limit,
|
||||
emqx_mgmt_api:select_table_with_count(Tab, Ms, Continuation, Limit,
|
||||
fun format_channel_info/1);
|
||||
|
||||
query(Tab, {Qs, Fuzzy}, Continuation, Limit) ->
|
||||
Ms = qs2ms(Qs),
|
||||
FuzzyFilterFun = fuzzy_filter_fun(Fuzzy),
|
||||
emqx_mgmt_api:select_table(Tab, {Ms, FuzzyFilterFun}, Continuation, Limit,
|
||||
emqx_mgmt_api:select_table_with_count(Tab, {Ms, FuzzyFilterFun}, Continuation, Limit,
|
||||
fun format_channel_info/1).
|
||||
|
||||
%%--------------------------------------------------------------------
|
||||
|
|
|
@ -107,7 +107,7 @@ generate_topic(Params) -> Params.
|
|||
|
||||
query(Tab, {Qs, _}, Continuation, Limit) ->
|
||||
Ms = qs2ms(Qs, [{{route, '_', '_'}, [], ['$_']}]),
|
||||
emqx_mgmt_api:select_table(Tab, Ms, Continuation, Limit, fun format/1).
|
||||
emqx_mgmt_api:select_table_with_count(Tab, Ms, Continuation, Limit, fun format/1).
|
||||
|
||||
qs2ms([], Res) -> Res;
|
||||
qs2ms([{topic,'=:=', T} | Qs], [{{route, _, N}, [], ['$_']}]) ->
|
||||
|
|
|
@ -150,12 +150,12 @@ format({_Subscriber, Topic, Options}) ->
|
|||
|
||||
query(Tab, {Qs, []}, Continuation, Limit) ->
|
||||
Ms = qs2ms(Qs),
|
||||
emqx_mgmt_api:select_table(Tab, Ms, Continuation, Limit, fun format/1);
|
||||
emqx_mgmt_api:select_table_with_count(Tab, Ms, Continuation, Limit, fun format/1);
|
||||
|
||||
query(Tab, {Qs, Fuzzy}, Continuation, Limit) ->
|
||||
Ms = qs2ms(Qs),
|
||||
FuzzyFilterFun = fuzzy_filter_fun(Fuzzy),
|
||||
emqx_mgmt_api:select_table(Tab, {Ms, FuzzyFilterFun}, Continuation, Limit, fun format/1).
|
||||
emqx_mgmt_api:select_table_with_count(Tab, {Ms, FuzzyFilterFun}, Continuation, Limit, fun format/1).
|
||||
|
||||
fuzzy_filter_fun(Fuzzy) ->
|
||||
fun(MsRaws) when is_list(MsRaws) ->
|
||||
|
|
Loading…
Reference in New Issue