Skip to content

Commit

Permalink
Merge pull request #344 from emqx/fix-sub-search
Browse files Browse the repository at this point in the history
fix: search failed when topic+qos
  • Loading branch information
zhongwencool authored Apr 21, 2022
2 parents 76e21d6 + b8e3bc7 commit 82c720d
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/emqx_mgmt_api_subscriptions.erl
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ update_ms(qos, X, {{Pid, Topic}, Opts}) ->
{{Pid, Topic}, Opts#{qos => X}}.

filter_subscriptions(Data0, Params) ->
Data1 = filter_by_key(qos, proplists:get_value(<<"qos">>, Params), Data0),
Data1 = filter_by_key(qos, qos(Params), Data0),
Data2 = filter_by_key(clientid, proplists:get_value(<<"clientid">>, Params), Data1),
case proplists:get_value(<<"share">>, Params) of
undefined -> Data2;
Expand All @@ -185,12 +185,19 @@ filter_subscriptions(Data0, Params) ->
Size = byte_size(Prefix),
lists:filter(fun(#{topic := Topic}) ->
case Topic of
<<Prefix:Size, _/binary>> -> true;
<<Prefix:Size/binary, _/binary>> -> true;
_ -> false
end
end,
Data2)
end.

qos(Params) ->
case proplists:get_value(<<"qos">>, Params) of
undefined -> undefined;
Qos when is_integer(Qos) -> Qos;
Qos when is_binary(Qos) -> binary_to_integer(Qos)
end.

filter_by_key(_Key, undefined, List) -> List;
filter_by_key(Key, Value, List) -> lists:filter(fun(E) -> Value =:= maps:get(Key, E) end, List).

0 comments on commit 82c720d

Please sign in to comment.