def init_hash_uuid_lut(session, hashes):
"""
From the list [x, y, z] of hashes return
a dictionary which tells if a chunk was `linked` or not:
{x: LinkageEntity, y: LinkageEntity, z: None}
"""
# Note: unhexlify is necessary since the database stores
# binary representations of the hashes
bin_hashes = [binascii.unhexlify(ahash.encode('utf-8'))
for ahash in hashes]
links = session.query(LinkageEntity).filter(
LinkageEntity.linkage_hash.in_(bin_hashes)).all()
links_cache = {link.friendly_hash(): link for link in links}
lut = {}
# Extra loop so we can provide an entry for hashes not found in the db
for ahash in hashes:
lut[ahash] = links_cache.get(ahash, None)
return lut
评论列表
文章目录