summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAsk Solem <ask@celeryproject.org>2013-09-12 21:51:49 +0100
committerAsk Solem <ask@celeryproject.org>2013-09-12 21:51:49 +0100
commite506b1f59afd4ecf7f8927b0d84ff41f4961b334 (patch)
treebb19ec48695da86a81eb48be52ce77162d0d610b
parentac4ae2576b98559c7d3ae707227c4ac5015817c1 (diff)
downloadkombu-e506b1f59afd4ecf7f8927b0d84ff41f4961b334.tar.gz
Declaration cache: Only keep hash of entity, and respect entity.can_cache_declaration
-rw-r--r--kombu/common.py18
-rw-r--r--kombu/entity.py4
2 files changed, 14 insertions, 8 deletions
diff --git a/kombu/common.py b/kombu/common.py
index 27b3f322..577071f6 100644
--- a/kombu/common.py
+++ b/kombu/common.py
@@ -94,12 +94,18 @@ def _maybe_declare(entity):
channel = entity.channel
if not channel.connection:
raise StdChannelError("channel disconnected")
- declared = channel.connection.client.declared_entities
- if entity not in declared or getattr(entity, 'auto_delete', None):
- entity.declare()
- declared.add(entity)
- return True
- return False
+
+ if entity.can_cache_declaration:
+ declared = channel.connection.client.declared_entities
+ ident = hash(entity)
+ if ident not in declared:
+ entity.declare()
+ declared.add(ident)
+ return True
+ return False
+
+ entity.declare()
+ return True
def _imaybe_declare(entity, **retry_policy):
diff --git a/kombu/entity.py b/kombu/entity.py
index 7f5bf4a7..d0a2c4aa 100644
--- a/kombu/entity.py
+++ b/kombu/entity.py
@@ -279,7 +279,7 @@ class Exchange(MaybeChannelBound):
@property
def can_cache_declaration(self):
- return self.durable
+ return self.durable and not self.auto_delete
class binding(object):
@@ -659,7 +659,7 @@ class Queue(MaybeChannelBound):
@property
def can_cache_declaration(self):
- return self.durable
+ return self.durable and not self.auto_delete
@classmethod
def from_dict(self, queue, **options):