diff 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
line wrap: on
line diff
--- a/libervia/pages/blog/page_meta.py	Fri Jan 11 16:38:25 2019 +0100
+++ b/libervia/pages/blog/page_meta.py	Fri Jan 11 16:39:46 2019 +0100
@@ -1,5 +1,6 @@
 #!/usr/bin/env python2.7
 # -*- coding: utf-8 -*-
+from sat.core.i18n import _
 from libervia.server.constants import Const as C
 from twisted.words.protocols.jabber import jid
 from twisted.internet import defer
@@ -36,14 +37,23 @@
         identities = template_data[u"identities"] = self.host.getSessionData(
             request, session_iface.ISATSession
         ).identities
+        d_list = []
         for entity_jid_s in entities:
             entities_url[entity_jid_s] = self.getPageByName("blog_view").getURL(
                 entity_jid_s
             )
             if entity_jid_s not in identities:
-                identities[entity_jid_s] = yield self.host.bridgeCall(
-                    u"identityGet", entity_jid_s, profile
-                )
+                d_list.append(self.host.bridgeCall(u"identityGet",
+                                                   entity_jid_s,
+                                                   profile))
+        identities_data = yield defer.DeferredList(d_list)
+        for idx, (success, identity) in enumerate(identities_data):
+            entity_jid_s = entities[idx]
+            if not success:
+                log.warning(_(u"Can't retrieve identity of {entity}")
+                    .format(entity=entity_jid_s))
+            else:
+                identities[entity_jid_s] = identity
 
 
 def on_data_post(self, request):