changeset 180:fc687620599b

Properly add send_last_published_item configuration item.
author Ralph Meijer <ralphm@ik.nu>
date Thu, 10 Apr 2008 14:33:50 +0000
parents 42e23a62b57f
children 0d4474051eeb
files idavoll/backend.py idavoll/memory_storage.py idavoll/pgsql_storage.py
diffstat 3 files changed, 18 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/idavoll/backend.py	Thu Apr 10 14:06:00 2008 +0000
+++ b/idavoll/backend.py	Thu Apr 10 14:33:50 2008 +0000
@@ -35,10 +35,15 @@
                "pubsub#deliver_payloads":
                   {"type": "boolean",
                    "label": "Deliver payloads with event notifications"},
+               "pubsub#send_last_published_item":
+                  {"type": "list-single",
+                   "label": "When to send the last published item',
+                   "options": {'never', 'on_sub'},
               }
 
     default_config = {"pubsub#persist_items": True,
                       "pubsub#deliver_payloads": True,
+                      "pubsub#send_last_published_item": 'on_sub',
                      }
 
     def __init__(self, storage):
--- a/idavoll/memory_storage.py	Thu Apr 10 14:06:00 2008 +0000
+++ b/idavoll/memory_storage.py	Thu Apr 10 14:33:50 2008 +0000
@@ -10,7 +10,7 @@
 
 default_config = {"pubsub#persist_items": True,
                   "pubsub#deliver_payloads": True,
-                  "pubsub#send_last_published_item": True,
+                  "pubsub#send_last_published_item": 'on_sub',
                   "pubsub#node_type": "leaf"}
 
 class Storage:
--- a/idavoll/pgsql_storage.py	Thu Apr 10 14:06:00 2008 +0000
+++ b/idavoll/pgsql_storage.py	Thu Apr 10 14:33:50 2008 +0000
@@ -28,12 +28,16 @@
 
     def _get_node(self, cursor, node_id):
         configuration = {}
-        cursor.execute("""SELECT persistent, deliver_payload FROM nodes
+        cursor.execute("""SELECT persistent, deliver_payload,
+                                 send_last_published_item
+                          FROM nodes
                           WHERE node=%s""",
                        (node_id,))
         try:
             (configuration["pubsub#persist_items"],
-             configuration["pubsub#deliver_payloads"]) = cursor.fetchone()
+             configuration["pubsub#deliver_payloads"],
+             configuration["pubsub#send_last_published_item") = \
+            cursor.fetchone()
         except TypeError:
             raise error.NodeNotFound()
         else:
@@ -138,17 +142,19 @@
         for option in options:
             if option in config:
                 config[option] = options[option]
-        
+
         d = self._dbpool.runInteraction(self._set_configuration, config)
         d.addCallback(self._set_cached_configuration, config)
         return d
 
     def _set_configuration(self, cursor, config):
         self._check_node_exists(cursor)
-        cursor.execute("""UPDATE nodes SET persistent=%s, deliver_payload=%s
+        cursor.execute("""UPDATE nodes SET persistent=%s, deliver_payload=%s,
+                                           send_last_published_item=%s
                           WHERE node=%s""",
                        (config["pubsub#persist_items"],
                         config["pubsub#deliver_payloads"],
+                        config["pubsub#send_last_published_item"],
                         self.id))
 
     def _set_cached_configuration(self, void, config):
@@ -300,7 +306,7 @@
                           WHERE node=%s""",
                        self.id)
         result = cursor.fetchall()
-        
+
         return [(jid.internJID(r[0]), r[1]) for r in result]
 
 class LeafNodeMixin:
@@ -340,7 +346,7 @@
 
     def _remove_items(self, cursor, item_ids):
         self._check_node_exists(cursor)
-        
+
         deleted = []
 
         for item_id in item_ids: