Skip to content

Commit 2254c8f

Browse files
sylvain-hhmichaelklishin
authored andcommitted
rabbit_router:match_bindings/2 optimize (uses ets:select directly); improves rabbit_exchange_type_headers, should improves rabbitmq_jms_topic_exchange too
(cherry picked from commit 6ff1fb7)
1 parent e6e3465 commit 2254c8f

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

src/rabbit_router.erl

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,14 @@
3636

3737
%%----------------------------------------------------------------------------
3838

39-
%% TODO: Maybe this should be handled by a cursor instead.
40-
%% TODO: This causes a full scan for each entry with the same source
39+
%% No need to call mnesia:dirty_select/2 (cf. note below), let alone go
40+
%% through qlc because query is so simple !
4141
match_bindings(SrcName, Match) ->
42-
Query = qlc:q([DestinationName ||
43-
#route{binding = Binding = #binding{
44-
source = SrcName1,
45-
destination = DestinationName}} <-
46-
mnesia:table(rabbit_route),
47-
SrcName == SrcName1,
48-
Match(Binding)]),
49-
mnesia:async_dirty(fun qlc:e/1, [Query]).
42+
MatchHead = #route{binding = #binding{source = SrcName,
43+
_ = '_'}},
44+
Routes = ets:select(rabbit_route, [{MatchHead, [], [['$_']]}]),
45+
[ Dest || [#route{binding = Binding = #binding{destination = Dest}}] <-
46+
Routes, Match(Binding)].
5047

5148
match_routing_key(SrcName, [RoutingKey]) ->
5249
find_routes(#route{binding = #binding{source = SrcName,

0 commit comments

Comments
 (0)