Skip to content

Commit

Permalink
Fasten wot graph generation with asyncio.gather
Browse files Browse the repository at this point in the history
  • Loading branch information
Insoleet committed Jan 29, 2016
1 parent cf9514b commit b86bc2c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
12 changes: 8 additions & 4 deletions src/sakia/core/graph/explorer_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,16 @@ async def _explore(self, identity, steps):

certifier_list, certified_list = await asyncio.gather(certifier_coro, certified_coro)

await self.add_certifier_list(certifier_list, current_identity, identity)
certifier_coro = asyncio.ensure_future(self.add_certifier_list(certifier_list,
current_identity, identity))
logging.debug("New identity certifiers : {pubkey}".format(pubkey=current_identity.pubkey[:5]))
self.graph_changed.emit()
await self.add_certified_list(certified_list, current_identity, identity)
certified_coro = asyncio.ensure_future(self.add_certified_list(certified_list,
current_identity, identity))
certifier_coro.add_done_callback(lambda f: self.graph_changed.emit())
certified_coro.add_done_callback(lambda f: self.graph_changed.emit())
await asyncio.gather(certifier_coro, certified_coro)

logging.debug("New identity certified : {pubkey}".format(pubkey=current_identity.pubkey[:5]))
self.graph_changed.emit()

for cert in certified_list + certifier_list:
if cert['identity'] not in explorable[step + 1]:
Expand Down
18 changes: 12 additions & 6 deletions src/sakia/core/graph/wot_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,21 @@ async def initialize(self, center_identity, account_identity):
self.add_identity(center_identity, node_status)

# create Identity from node metadata
certifier_list = await center_identity.unique_valid_certifiers_of(self.app.identities_registry,
self.community)
certified_list = await center_identity.unique_valid_certified_by(self.app.identities_registry,
self.community)
certifier_coro = asyncio.ensure_future(center_identity.unique_valid_certifiers_of(self.app.identities_registry,
self.community))
certified_coro = asyncio.ensure_future(center_identity.unique_valid_certified_by(self.app.identities_registry,
self.community))

certifier_list, certified_list = await asyncio.gather(certifier_coro, certified_coro)

# populate graph with certifiers-of
await self.add_certifier_list(certifier_list, center_identity, account_identity)
certifier_coro = asyncio.ensure_future(self.add_certifier_list(certifier_list,
center_identity, account_identity))
# populate graph with certified-by
await self.add_certified_list(certified_list, center_identity, account_identity)
certified_coro = asyncio.ensure_future(self.add_certified_list(certified_list,
center_identity, account_identity))

await asyncio.gather(certifier_coro, certified_coro)

async def get_shortest_path_to_identity(self, account_identity, to_identity):
"""
Expand Down

0 comments on commit b86bc2c

Please sign in to comment.