Skip to content

Commit 107c03f

Browse files
committed
rabbit_db_exchange: Use Khepri projection for count/0 and exists/1
These functions will be used in the child commit for a check on the number of exchanges. We can use the projection to avoid bothering the Khepri process with a query.
1 parent 5c26be6 commit 107c03f

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

deps/rabbit/src/rabbit_db_exchange.erl

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -266,10 +266,11 @@ count_in_mnesia() ->
266266
mnesia:table_info(?MNESIA_TABLE, size).
267267

268268
count_in_khepri() ->
269-
Path = khepri_exchange_path(?KHEPRI_WILDCARD_STAR, ?KHEPRI_WILDCARD_STAR),
270-
case rabbit_khepri:count(Path) of
271-
{ok, Count} -> Count;
272-
_ -> 0
269+
try
270+
ets:info(?KHEPRI_PROJECTION, size)
271+
catch
272+
error:badarg ->
273+
0
273274
end.
274275

275276
%% -------------------------------------------------------------------
@@ -869,7 +870,12 @@ exists_in_mnesia(Name) ->
869870
ets:member(?MNESIA_TABLE, Name).
870871

871872
exists_in_khepri(Name) ->
872-
rabbit_khepri:exists(khepri_exchange_path(Name)).
873+
try
874+
ets:member(?KHEPRI_PROJECTION, Name)
875+
catch
876+
error:badarg ->
877+
false
878+
end.
873879

874880
%% -------------------------------------------------------------------
875881
%% clear().

0 commit comments

Comments
 (0)