diff options
author | Ask Solem <ask@celeryproject.org> | 2013-09-12 21:51:49 +0100 |
---|---|---|
committer | Ask Solem <ask@celeryproject.org> | 2013-09-12 21:51:49 +0100 |
commit | e506b1f59afd4ecf7f8927b0d84ff41f4961b334 (patch) | |
tree | bb19ec48695da86a81eb48be52ce77162d0d610b | |
parent | ac4ae2576b98559c7d3ae707227c4ac5015817c1 (diff) | |
download | kombu-e506b1f59afd4ecf7f8927b0d84ff41f4961b334.tar.gz |
Declaration cache: Only keep hash of entity, and respect entity.can_cache_declaration
-rw-r--r-- | kombu/common.py | 18 | ||||
-rw-r--r-- | kombu/entity.py | 4 |
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): |