Mercurial > libervia-pubsub
comparison idavoll/pgsql_storage.py @ 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 | 246911bcb699 |
children | 0d4474051eeb |
comparison
equal
deleted
inserted
replaced
179:42e23a62b57f | 180:fc687620599b |
---|---|
26 def get_node(self, node_id): | 26 def get_node(self, node_id): |
27 return self._dbpool.runInteraction(self._get_node, node_id) | 27 return self._dbpool.runInteraction(self._get_node, node_id) |
28 | 28 |
29 def _get_node(self, cursor, node_id): | 29 def _get_node(self, cursor, node_id): |
30 configuration = {} | 30 configuration = {} |
31 cursor.execute("""SELECT persistent, deliver_payload FROM nodes | 31 cursor.execute("""SELECT persistent, deliver_payload, |
32 send_last_published_item | |
33 FROM nodes | |
32 WHERE node=%s""", | 34 WHERE node=%s""", |
33 (node_id,)) | 35 (node_id,)) |
34 try: | 36 try: |
35 (configuration["pubsub#persist_items"], | 37 (configuration["pubsub#persist_items"], |
36 configuration["pubsub#deliver_payloads"]) = cursor.fetchone() | 38 configuration["pubsub#deliver_payloads"], |
39 configuration["pubsub#send_last_published_item") = \ | |
40 cursor.fetchone() | |
37 except TypeError: | 41 except TypeError: |
38 raise error.NodeNotFound() | 42 raise error.NodeNotFound() |
39 else: | 43 else: |
40 node = LeafNode(node_id, configuration) | 44 node = LeafNode(node_id, configuration) |
41 node._dbpool = self._dbpool | 45 node._dbpool = self._dbpool |
136 config = copy.copy(self._config) | 140 config = copy.copy(self._config) |
137 | 141 |
138 for option in options: | 142 for option in options: |
139 if option in config: | 143 if option in config: |
140 config[option] = options[option] | 144 config[option] = options[option] |
141 | 145 |
142 d = self._dbpool.runInteraction(self._set_configuration, config) | 146 d = self._dbpool.runInteraction(self._set_configuration, config) |
143 d.addCallback(self._set_cached_configuration, config) | 147 d.addCallback(self._set_cached_configuration, config) |
144 return d | 148 return d |
145 | 149 |
146 def _set_configuration(self, cursor, config): | 150 def _set_configuration(self, cursor, config): |
147 self._check_node_exists(cursor) | 151 self._check_node_exists(cursor) |
148 cursor.execute("""UPDATE nodes SET persistent=%s, deliver_payload=%s | 152 cursor.execute("""UPDATE nodes SET persistent=%s, deliver_payload=%s, |
153 send_last_published_item=%s | |
149 WHERE node=%s""", | 154 WHERE node=%s""", |
150 (config["pubsub#persist_items"], | 155 (config["pubsub#persist_items"], |
151 config["pubsub#deliver_payloads"], | 156 config["pubsub#deliver_payloads"], |
157 config["pubsub#send_last_published_item"], | |
152 self.id)) | 158 self.id)) |
153 | 159 |
154 def _set_cached_configuration(self, void, config): | 160 def _set_cached_configuration(self, void, config): |
155 self._config = config | 161 self._config = config |
156 | 162 |
298 JOIN entities ON | 304 JOIN entities ON |
299 (affiliations.entity_id = entities.id) | 305 (affiliations.entity_id = entities.id) |
300 WHERE node=%s""", | 306 WHERE node=%s""", |
301 self.id) | 307 self.id) |
302 result = cursor.fetchall() | 308 result = cursor.fetchall() |
303 | 309 |
304 return [(jid.internJID(r[0]), r[1]) for r in result] | 310 return [(jid.internJID(r[0]), r[1]) for r in result] |
305 | 311 |
306 class LeafNodeMixin: | 312 class LeafNodeMixin: |
307 | 313 |
308 type = 'leaf' | 314 type = 'leaf' |
338 def remove_items(self, item_ids): | 344 def remove_items(self, item_ids): |
339 return self._dbpool.runInteraction(self._remove_items, item_ids) | 345 return self._dbpool.runInteraction(self._remove_items, item_ids) |
340 | 346 |
341 def _remove_items(self, cursor, item_ids): | 347 def _remove_items(self, cursor, item_ids): |
342 self._check_node_exists(cursor) | 348 self._check_node_exists(cursor) |
343 | 349 |
344 deleted = [] | 350 deleted = [] |
345 | 351 |
346 for item_id in item_ids: | 352 for item_id in item_ids: |
347 cursor.execute("""DELETE FROM items WHERE | 353 cursor.execute("""DELETE FROM items WHERE |
348 node_id=(SELECT id FROM nodes WHERE node=%s) AND | 354 node_id=(SELECT id FROM nodes WHERE node=%s) AND |