Переглянути джерело

Code Cleanup and Optimisation

Tuna Celik 5 роки тому
батько
коміт
ecff5fac82
2 змінених файлів з 12 додано та 11 видалено
  1. 3 2
      radicale/app/delete.py
  2. 9 9
      radicale/hook/rabbitmq/__init__.py

+ 3 - 2
radicale/app/delete.py

@@ -64,10 +64,11 @@ class ApplicationDeleteMixin:
                 # ETag precondition not verified, do not delete item
                 return httputils.PRECONDITION_FAILED
             if isinstance(item, storage.BaseCollection):
+                cache_items = item.get_all()
                 xml_answer = xml_delete(base_prefix, path, item)
-                for i in item.get_all():
+                for cache_item in cache_items:
                     hook_notification_item = HookNotificationItem(
-                        HookNotificationItemTypes.DELETE, i.uid)
+                        HookNotificationItemTypes.DELETE, cache_item.uid)
                     self._hook.notify(hook_notification_item)
             else:
                 xml_answer = xml_delete(

+ 9 - 9
radicale/hook/rabbitmq/__init__.py

@@ -9,24 +9,24 @@ class Hook(hook.BaseHook):
     def __init__(self, configuration):
         super().__init__(configuration)
         endpoint = configuration.get("hook", "rabbitmq_endpoint")
-        self.topic = configuration.get("hook", "rabbitmq_topic")
-        self.encoding = configuration.get("encoding", "stock")
+        self._topic = configuration.get("hook", "rabbitmq_topic")
+        self._encoding = configuration.get("encoding", "stock")
 
         self._make_connection_synced(endpoint)
-        self._make_declare_queue_synced(self.topic)
+        self._make_declare_queue_synced(self._topic)
 
     def _make_connection_synced(self, endpoint):
         parameters = pika.URLParameters(endpoint)
-        self.connection = pika.BlockingConnection(parameters)
-        self.channel = self.connection.channel()
+        connection = pika.BlockingConnection(parameters)
+        self._channel = connection.channel()
 
     def _make_declare_queue_synced(self, topic):
-        self.channel.queue_declare(queue=topic)
+        self._channel.queue_declare(queue=topic)
 
     def notify(self, notification_item):
         if isinstance(notification_item, HookNotificationItem):
-            self.channel.basic_publish(
+            self._channel.basic_publish(
                 exchange='',
-                routing_key=self.topic,
-                body=notification_item.to_json().encode(encoding=self.encoding)
+                routing_key=self._topic,
+                body=notification_item.to_json().encode(encoding=self._encoding)
             )