comparison sat_pubsub/pgsql_storage.py @ 337:57a3051ee435

storage (pgsql): added getLastItems method, to get last items from a series of nodes and entities (needed for PEP compliance).
author Goffi <goffi@goffi.org>
date Sat, 12 Aug 2017 18:11:36 +0200
parents 31cbd8b9fa7f
children b49f75a26156
comparison
equal deleted inserted replaced
336:a468c187bbb5 337:57a3051ee435
335 335
336 336
337 def getDefaultConfiguration(self, nodeType): 337 def getDefaultConfiguration(self, nodeType):
338 return self.defaultConfig[nodeType] 338 return self.defaultConfig[nodeType]
339 339
340
341 def formatLastItems(self, result):
342 last_items = []
343 for pep_jid_s, node, data, item_access_model in result:
344 pep_jid = jid.JID(pep_jid_s)
345 item = generic.stripNamespace(parseXml(data))
346 last_items.append((pep_jid, node, item, item_access_model))
347 return last_items
348
349
350 def getLastItems(self, entities, nodes, node_accesses, item_accesses, pep):
351 """get last item for several nodes and entities in a single request"""
352 if not entities or not nodes or not node_accesses or not item_accesses:
353 raise ValueError("entities, nodes and accesses must not be empty")
354 if node_accesses != ('open',) or item_accesses != ('open',):
355 raise NotImplementedError('only "open" access model is handled for now')
356 if not pep:
357 raise NotImplementedError(u"getLastItems is only implemented for PEP at the moment")
358 d = self.dbpool.runQuery("""SELECT DISTINCT ON (node_id) pep, node, data, items.access_model
359 FROM items
360 NATURAL JOIN nodes
361 WHERE nodes.pep IN %s
362 AND node IN %s
363 AND nodes.access_model in %s
364 AND items.access_model in %s
365 ORDER BY node_id DESC, item_id DESC""",
366 (tuple([e.userhost() for e in entities]),
367 nodes,
368 node_accesses,
369 item_accesses))
370 d.addCallback(self.formatLastItems)
371 return d
340 372
341 373
342 class Node: 374 class Node:
343 375
344 implements(iidavoll.INode) 376 implements(iidavoll.INode)