perf(emqx_placeholder): do not try to decode maps as json

fix
This commit is contained in:
Ilya Averyanov 2024-05-24 19:37:00 +03:00
parent 2908da4a8a
commit 327080e70e
2 changed files with 15 additions and 11 deletions

View File

@ -265,11 +265,16 @@ lookup_var(Var, Value) when Var == ?PH_VAR_THIS orelse Var == [] ->
Value; Value;
lookup_var([Prop | Rest], Data0) -> lookup_var([Prop | Rest], Data0) ->
Data = Data =
case emqx_utils_json:safe_decode(Data0, [return_maps]) of case is_map(Data0) of
{ok, Data1} -> true ->
Data1; Data0;
{error, _} -> false ->
Data0 case emqx_utils_json:safe_decode(Data0, [return_maps]) of
{ok, Data1} ->
Data1;
{error, _} ->
Data0
end
end, end,
case lookup(Prop, Data) of case lookup(Prop, Data) of
{ok, Value} -> {ok, Value} ->
@ -293,12 +298,10 @@ lookup(Prop, Data) when is_binary(Prop) ->
end. end.
do_one_lookup(Key, Data) -> do_one_lookup(Key, Data) ->
try case Data of
{ok, maps:get(Key, Data)} #{Key := Value} ->
catch {ok, Value};
error:{badkey, _} -> _ ->
{error, undefined};
error:{badmap, _} ->
{error, undefined} {error, undefined}
end. end.

View File

@ -0,0 +1 @@
Improve performance of template rendering in bridges.