Mercurial > libervia-pubsub
comparison idavoll/pgsql_storage.py @ 146:b4490bdc77e5
Change semantics of Node.is_subscribed() to match all subscriptions for an
entity (all resources).
author | Ralph Meijer <ralphm@ik.nu> |
---|---|
date | Fri, 29 Jul 2005 15:33:43 +0000 |
parents | f393bccec4bc |
children | b03e5ad81173 |
comparison
equal
deleted
inserted
replaced
145:f393bccec4bc | 146:b4490bdc77e5 |
---|---|
256 return cursor.fetchall() | 256 return cursor.fetchall() |
257 | 257 |
258 def _convert_to_jids(self, list): | 258 def _convert_to_jids(self, list): |
259 return [jid.JID("%s/%s" % (l[0], l[1])) for l in list] | 259 return [jid.JID("%s/%s" % (l[0], l[1])) for l in list] |
260 | 260 |
261 def is_subscribed(self, subscriber): | 261 def is_subscribed(self, entity): |
262 return self._dbpool.runInteraction(self._is_subscribed, subscriber) | 262 return self._dbpool.runInteraction(self._is_subscribed, entity) |
263 | 263 |
264 def _is_subscribed(self, cursor, subscriber): | 264 def _is_subscribed(self, cursor, entity): |
265 self._check_node_exists(cursor) | 265 self._check_node_exists(cursor) |
266 | |
267 userhost = subscriber.userhost() | |
268 resource = subscriber.resource or '' | |
269 | 266 |
270 cursor.execute("""SELECT 1 FROM entities | 267 cursor.execute("""SELECT 1 FROM entities |
271 JOIN subscriptions ON | 268 JOIN subscriptions ON |
272 (entities.id=subscriptions.entity_id) | 269 (entities.id=subscriptions.entity_id) |
273 JOIN nodes ON | 270 JOIN nodes ON |
274 (nodes.id=subscriptions.node_id) | 271 (nodes.id=subscriptions.node_id) |
275 WHERE entities.jid=%s AND resource=%s | 272 WHERE entities.jid=%s |
276 AND node=%s AND subscription='subscribed'""", | 273 AND node=%s AND subscription='subscribed'""", |
277 (userhost, | 274 (entity.userhost(), |
278 resource, | |
279 self.id)) | 275 self.id)) |
280 | 276 |
281 return cursor.fetchone() is not None | 277 return cursor.fetchone() is not None |
282 | 278 |
283 def get_affiliations(self): | 279 def get_affiliations(self): |
295 self.id) | 291 self.id) |
296 result = cursor.fetchall() | 292 result = cursor.fetchall() |
297 | 293 |
298 return [(jid.JID(r[0]), r[1]) for r in result] | 294 return [(jid.JID(r[0]), r[1]) for r in result] |
299 | 295 |
300 class LeafNode(Node): | 296 class LeafNodeMixin: |
301 | |
302 implements(storage.ILeafNode) | |
303 | 297 |
304 type = 'leaf' | 298 type = 'leaf' |
305 | 299 |
306 def store_items(self, items, publisher): | 300 def store_items(self, items, publisher): |
307 return self._dbpool.runInteraction(self._store_items, items, publisher) | 301 return self._dbpool.runInteraction(self._store_items, items, publisher) |
393 self._check_node_exists(cursor) | 387 self._check_node_exists(cursor) |
394 | 388 |
395 cursor.execute("""DELETE FROM items WHERE | 389 cursor.execute("""DELETE FROM items WHERE |
396 node_id=(SELECT id FROM nodes WHERE node=%s)""", | 390 node_id=(SELECT id FROM nodes WHERE node=%s)""", |
397 (self.id,)) | 391 (self.id,)) |
392 | |
393 class LeafNode(Node, LeafNodeMixin): | |
394 | |
395 implements(storage.ILeafNode) |