Ver código fonte

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
Thales Macedo Garitezi 2 anos atrás
pai
commit
d126c7dc62

+ 1 - 1
apps/emqx_bridge/src/emqx_bridge.app.src

@@ -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, [

+ 1 - 1
apps/emqx_rule_engine/src/emqx_rule_engine.app.src

@@ -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]},

+ 15 - 12
apps/emqx_rule_engine/src/emqx_rule_engine.erl

@@ -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).