diff options
author | Ben Hood <0x6e6562@gmail.com> | 2008-10-06 17:29:23 +0100 |
---|---|---|
committer | Ben Hood <0x6e6562@gmail.com> | 2008-10-06 17:29:23 +0100 |
commit | 522912487e3420b39c973814415356ef41b11eaf (patch) | |
tree | f186f67d4c810f9d8a620b9884ce524f3e182483 | |
parent | 28a801a36eb9ad13c8b7baed2404ffc31f72d443 (diff) | |
download | rabbitmq-server-522912487e3420b39c973814415356ef41b11eaf.tar.gz |
Further refactorings
-rw-r--r-- | src/rabbit_exchange.erl | 27 |
1 files changed, 10 insertions, 17 deletions
diff --git a/src/rabbit_exchange.erl b/src/rabbit_exchange.erl index 5fff049b..5811b055 100644 --- a/src/rabbit_exchange.erl +++ b/src/rabbit_exchange.erl @@ -43,7 +43,7 @@ -import(qlc). -import(regexp). --define(CHUNK_SIZE, 10). +-define(CHUNK_SIZE, 1). %%---------------------------------------------------------------------------- @@ -230,8 +230,7 @@ delete_bindings(Binding = #binding{exchange_name = X, call_with_exchange(ExchangeName, fun(Exchange) -> if Exchange#exchange.auto_delete -> - Predicate = fun(E) -> E == QueueName end, - case has_bindings(ExchangeName, Predicate) of + case has_bindings(ExchangeName, QueueName) of true -> ok; false -> unchecked_internal_delete(ExchangeName) @@ -273,27 +272,21 @@ exchanges_for_queue(QueueName) -> queue_name = QueueName, key = '_'}}, sets:to_list(sets:from_list( - mnesia:dirty_select(reverse_route, [{MatchHead, [], ['$1']}]))). + mnesia:select(reverse_route, [{MatchHead, [], ['$1']}]))). has_bindings(ExchangeName) -> - has_bindings(ExchangeName, fun(_) -> false end). + has_bindings_helper(ExchangeName, []). -has_bindings(ExchangeName, Predicate) -> +has_bindings(ExchangeName, QueueName) -> + has_bindings_helper(ExchangeName, [{'=/=', '$1', {QueueName}}]). + +has_bindings_helper(ExchangeName, Condition) -> MatchHead = #route{binding = #binding{exchange_name = ExchangeName, queue_name = '$1', key = '_'}}, - continue(fun() -> mnesia:select(route, - [{MatchHead, [], ['$1']}], ?CHUNK_SIZE, write) - end, Predicate). - -continue(Fun, Predicate) -> - case Fun() of + case mnesia:select(route, [{MatchHead, Condition, ['$1']}], ?CHUNK_SIZE, write) of '$end_of_table' -> false; - {Routes, Cont} -> - case lists:dropwhile(Predicate, Routes) of - [] -> continue(fun() -> mnesia:select(Cont) end, Predicate); - _ -> true - end + _ -> true end. call_with_exchange(Exchange, Fun) -> |