Skip to content

Commit c45b4d7

Browse files
Introduce rabbit_{exchange,amqqueue}:lookup_many/1
rabbit_amqqueue:lookup/1 already supports lists of keys but it makes less sense for rabbit_exchange:lookup/1. This introduces a uniform API element that can be used to look up N entities by key while preserving the historically accumulated difference that stems from the common access patterns for each entity type. (cherry picked from commit 4216b2a)
1 parent b075151 commit c45b4d7

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

src/rabbit_amqqueue.erl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
forget_all_durable/1, delete_crashed/1, delete_crashed/2,
2323
delete_crashed_internal/2]).
2424
-export([pseudo_queue/2, pseudo_queue/3, immutable/1]).
25-
-export([lookup/1, not_found_or_absent/1, with/2, with/3, with_or_die/2,
25+
-export([lookup/1, lookup_many/1, not_found_or_absent/1, with/2, with/3, with_or_die/2,
2626
assert_equivalence/5,
2727
check_exclusive_access/2, with_exclusive_access_or_die/3,
2828
stat/1, deliver/2, deliver/3, requeue/4, ack/4, reject/5]).
@@ -488,6 +488,11 @@ lookup(Names) when is_list(Names) ->
488488
lookup(Name) ->
489489
rabbit_misc:dirty_read({rabbit_queue, Name}).
490490

491+
-spec lookup_many ([name()]) -> [amqqueue:amqqueue()].
492+
493+
lookup_many(Names) when is_list(Names) ->
494+
lookup(Names).
495+
491496
-spec not_found_or_absent(name()) -> not_found_or_absent().
492497

493498
not_found_or_absent(Name) ->

src/rabbit_exchange.erl

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
-export([recover/1, policy_changed/2, callback/4, declare/7,
2222
assert_equivalence/6, assert_args_equivalence/2, check_type/1,
23-
lookup/1, lookup_or_die/1, list/0, list/1, lookup_scratch/2,
23+
lookup/1, lookup_many/1, lookup_or_die/1, list/0, list/1, lookup_scratch/2,
2424
update_scratch/3, update_decorators/1, immutable/1,
2525
info_keys/0, info/1, info/2, info_all/1, info_all/2, info_all/4,
2626
route/2, delete/3, validate_binding/2, count/0]).
@@ -219,19 +219,22 @@ assert_args_equivalence(#exchange{ name = Name, arguments = Args },
219219

220220
-spec lookup
221221
(name()) -> rabbit_types:ok(rabbit_types:exchange()) |
222-
rabbit_types:error('not_found');
223-
([name()]) ->
224-
[rabbit_types:exchange()].
222+
rabbit_types:error('not_found').
225223

226-
lookup([]) -> [];
227-
lookup([Name]) -> ets:lookup(rabbit_exchange, Name);
228-
lookup(Names) when is_list(Names) ->
229-
%% Normally we'd call mnesia:dirty_read/1 here, but that is quite
230-
%% expensive for reasons explained in rabbit_misc:dirty_read/1.
231-
lists:append([ets:lookup(rabbit_exchange, Name) || Name <- Names]);
232224
lookup(Name) ->
233225
rabbit_misc:dirty_read({rabbit_exchange, Name}).
234226

227+
228+
-spec lookup_many([name()]) -> [rabbit_types:exchange()].
229+
230+
lookup_many([]) -> [];
231+
lookup_many([Name]) -> ets:lookup(rabbit_exchange, Name);
232+
lookup_many(Names) when is_list(Names) ->
233+
%% Normally we'd call mnesia:dirty_read/1 here, but that is quite
234+
%% expensive for reasons explained in rabbit_misc:dirty_read/1.
235+
lists:append([ets:lookup(rabbit_exchange, Name) || Name <- Names]).
236+
237+
235238
-spec lookup_or_die
236239
(name()) -> rabbit_types:exchange() |
237240
rabbit_types:channel_exit().

0 commit comments

Comments
 (0)