refactor(rule_engine): use more helper functions

Follow up to
https://github.com/emqx/emqx/pull/10251#discussion_r1150710899 and
https://github.com/emqx/emqx/pull/10251#discussion_r1150720420
This commit is contained in:
Thales Macedo Garitezi 2023-03-28 11:32:38 -03:00
parent 1824e7efcc
commit d126c7dc62
3 changed files with 17 additions and 14 deletions

View File

@ -1,7 +1,7 @@
%% -*- mode: erlang -*-
{application, emqx_bridge, [
{description, "EMQX bridges"},
{vsn, "0.1.13"},
{vsn, "0.1.14"},
{registered, [emqx_bridge_sup]},
{mod, {emqx_bridge_app, []}},
{applications, [

View File

@ -2,7 +2,7 @@
{application, emqx_rule_engine, [
{description, "EMQX Rule Engine"},
% strict semver, bump manually!
{vsn, "5.0.11"},
{vsn, "5.0.12"},
{modules, []},
{registered, [emqx_rule_engine_sup, emqx_rule_engine]},
{applications, [kernel, stdlib, rulesql, getopt, emqx_ctl]},

View File

@ -319,14 +319,8 @@ get_basic_usage_info() ->
ReferencedBridges =
lists:foldl(
fun(#{actions := Actions, from := Froms}, Acc) ->
BridgeIDs0 =
[
BridgeID
|| From <- Froms,
{ok, BridgeID} <-
[emqx_bridge_resource:bridge_hookpoint_to_bridge_id(From)]
],
BridgeIDs1 = lists:filter(fun is_binary/1, Actions),
BridgeIDs0 = get_referenced_hookpoints(Froms),
BridgeIDs1 = get_egress_bridges(Actions),
tally_referenced_bridges(BridgeIDs0 ++ BridgeIDs1, Acc)
end,
#{},
@ -490,10 +484,8 @@ forwards_to_bridge(Actions, BridgeId) ->
lists:any(fun(A) -> A =:= BridgeId end, Actions).
references_ingress_bridge(Froms, BridgeId) ->
lists:any(
fun(ReferenceBridgeId) ->
BridgeId =:= ReferenceBridgeId
end,
lists:member(
BridgeId,
[
RefBridgeId
|| From <- Froms,
@ -501,3 +493,14 @@ references_ingress_bridge(Froms, BridgeId) ->
[emqx_bridge_resource:bridge_hookpoint_to_bridge_id(From)]
]
).
get_referenced_hookpoints(Froms) ->
[
BridgeID
|| From <- Froms,
{ok, BridgeID} <-
[emqx_bridge_resource:bridge_hookpoint_to_bridge_id(From)]
].
get_egress_bridges(Actions) ->
lists:filter(fun is_binary/1, Actions).