Mercurial > libervia-pubsub
comparison sat_pubsub/backend.py @ 339:516b282aa542
backend (notifications): avoid useless database request in getNotifications
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 20 Aug 2017 10:59:47 +0200 |
parents | a468c187bbb5 |
children | 567e486bce24 |
comparison
equal
deleted
inserted
replaced
338:6d059f07c2d3 | 339:516b282aa542 |
---|---|
360 item_data.item.children = [] | 360 item_data.item.children = [] |
361 self.dispatch({'items_data': items_data, 'node': node, 'pep': pep, 'recipient': recipient}, | 361 self.dispatch({'items_data': items_data, 'node': node, 'pep': pep, 'recipient': recipient}, |
362 '//event/pubsub/notify') | 362 '//event/pubsub/notify') |
363 | 363 |
364 | 364 |
365 def getNotifications(self, nodeDbId, items_data): | 365 def getNotifications(self, node, items_data): |
366 """Build a list of subscriber to the node | 366 """Build a list of subscriber to the node |
367 | 367 |
368 subscribers will be associated with subscribed items, | 368 subscribers will be associated with subscribed items, |
369 and subscription type. | 369 and subscription type. |
370 """ | 370 """ |
386 | 386 |
387 def rootNotFound(failure): | 387 def rootNotFound(failure): |
388 failure.trap(error.NodeNotFound) | 388 failure.trap(error.NodeNotFound) |
389 return [] | 389 return [] |
390 | 390 |
391 d1 = self.storage.getNodeById(nodeDbId) | 391 d1 = node.getSubscriptions('subscribed') |
392 d1.addCallback(lambda node: node.getSubscriptions('subscribed')) | |
393 # FIXME: must add root node subscriptions ? | 392 # FIXME: must add root node subscriptions ? |
394 # d2 = self.storage.getNode('', False) # FIXME: to check | 393 # d2 = self.storage.getNode('', False) # FIXME: to check |
395 # d2.addCallback(lambda node: node.getSubscriptions('subscribed')) | 394 # d2.addCallback(lambda node: node.getSubscriptions('subscribed')) |
396 # d2.addErrback(rootNotFound) | 395 # d2.addErrback(rootNotFound) |
397 # d = defer.gatherResults([d1, d2]) | 396 # d = defer.gatherResults([d1, d2]) |
1122 - items_data | 1121 - items_data |
1123 """ | 1122 """ |
1124 | 1123 |
1125 | 1124 |
1126 if subscription is None: | 1125 if subscription is None: |
1127 notifications = yield self.backend.getNotifications(node.nodeDbId, items_data) | 1126 notifications = yield self.backend.getNotifications(node, items_data) |
1128 else: | 1127 else: |
1129 notifications = [(subscription.subscriber, [subscription], items_data)] | 1128 notifications = [(subscription.subscriber, [subscription], items_data)] |
1130 | 1129 |
1131 owners = yield node.getOwners() | 1130 owners = yield node.getOwners() |
1132 owner_roster = None | 1131 owner_roster = None |