comparison libervia/pages/blog/page_meta.py @ 1139:e45480b6ba24

pages (blog): use DeferredList while discovering identities instead or waiting for each request individually.
author Goffi <goffi@goffi.org>
date Fri, 11 Jan 2019 16:39:46 +0100
parents 28e3eb3bb217
children 29eb15062416
comparison
equal deleted inserted replaced
1138:ef565839dada 1139:e45480b6ba24
1 #!/usr/bin/env python2.7 1 #!/usr/bin/env python2.7
2 # -*- coding: utf-8 -*- 2 # -*- coding: utf-8 -*-
3 from sat.core.i18n import _
3 from libervia.server.constants import Const as C 4 from libervia.server.constants import Const as C
4 from twisted.words.protocols.jabber import jid 5 from twisted.words.protocols.jabber import jid
5 from twisted.internet import defer 6 from twisted.internet import defer
6 from libervia.server import session_iface 7 from libervia.server import session_iface
7 from sat.core.log import getLogger 8 from sat.core.log import getLogger
34 ) 35 )
35 entities_url = template_data[u"entities_url"] = {} 36 entities_url = template_data[u"entities_url"] = {}
36 identities = template_data[u"identities"] = self.host.getSessionData( 37 identities = template_data[u"identities"] = self.host.getSessionData(
37 request, session_iface.ISATSession 38 request, session_iface.ISATSession
38 ).identities 39 ).identities
40 d_list = []
39 for entity_jid_s in entities: 41 for entity_jid_s in entities:
40 entities_url[entity_jid_s] = self.getPageByName("blog_view").getURL( 42 entities_url[entity_jid_s] = self.getPageByName("blog_view").getURL(
41 entity_jid_s 43 entity_jid_s
42 ) 44 )
43 if entity_jid_s not in identities: 45 if entity_jid_s not in identities:
44 identities[entity_jid_s] = yield self.host.bridgeCall( 46 d_list.append(self.host.bridgeCall(u"identityGet",
45 u"identityGet", entity_jid_s, profile 47 entity_jid_s,
46 ) 48 profile))
49 identities_data = yield defer.DeferredList(d_list)
50 for idx, (success, identity) in enumerate(identities_data):
51 entity_jid_s = entities[idx]
52 if not success:
53 log.warning(_(u"Can't retrieve identity of {entity}")
54 .format(entity=entity_jid_s))
55 else:
56 identities[entity_jid_s] = identity
47 57
48 58
49 def on_data_post(self, request): 59 def on_data_post(self, request):
50 jid_str = self.getPostedData(request, u"jid") 60 jid_str = self.getPostedData(request, u"jid")
51 try: 61 try: