Skip to content

Commit e9abf90

Browse files
the-mikedavismergify[bot]
authored andcommitted
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. (cherry picked from commit 392e5f9)
1 parent 8318530 commit e9abf90

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
%% -------------------------------------------------------------------
@@ -863,7 +864,12 @@ exists_in_mnesia(Name) ->
863864
ets:member(?MNESIA_TABLE, Name).
864865

865866
exists_in_khepri(Name) ->
866-
rabbit_khepri:exists(khepri_exchange_path(Name)).
867+
try
868+
ets:member(?KHEPRI_PROJECTION, Name)
869+
catch
870+
error:badarg ->
871+
false
872+
end.
867873

868874
%% -------------------------------------------------------------------
869875
%% clear().

0 commit comments

Comments
 (0)