Просмотр исходного кода

refactor: improve bookkeeping api

Thales Macedo Garitezi 1 год назад
Родитель
Сommit
6da71200f3

+ 1 - 3
apps/emqx_cluster_link/src/emqx_cluster_link_bookkeeper.erl

@@ -83,9 +83,7 @@ handle_tally_routes() ->
     ok.
 
 tally_routes([ClusterName | ClusterNames]) ->
-    Tab = emqx_cluster_link_extrouter:extroute_tab(),
-    Pat = emqx_cluster_link_extrouter:cluster_routes_ms(ClusterName),
-    NumRoutes = ets:select_count(Tab, Pat),
+    NumRoutes = emqx_cluster_link_extrouter:count(ClusterName),
     emqx_cluster_link_metrics:routes_set(ClusterName, NumRoutes),
     tally_routes(ClusterNames);
 tally_routes([]) ->

+ 4 - 6
apps/emqx_cluster_link/src/emqx_cluster_link_extrouter.erl

@@ -35,7 +35,7 @@
 ]).
 
 %% Internal export for bookkeeping
--export([cluster_routes_ms/1, extroute_tab/0]).
+-export([count/1]).
 
 %% Strictly monotonically increasing integer.
 -type smint() :: integer().
@@ -151,16 +151,14 @@ make_extroute_rec_pat(Entry) ->
     ).
 
 %% Internal exports for bookkeeping
-cluster_routes_ms(ClusterName) ->
+count(ClusterName) ->
     TopicPat = '_',
     RouteIDPat = '_',
     Pat = make_extroute_rec_pat(
         emqx_trie_search:make_pat(TopicPat, ?ROUTE_ID(ClusterName, RouteIDPat))
     ),
-    [{Pat, [], [true]}].
-
-extroute_tab() ->
-    ?EXTROUTE_TAB.
+    MS = [{Pat, [], [true]}],
+    ets:select_count(?EXTROUTE_TAB, MS).
 
 %%