Changeset View
Changeset View
Standalone View
Standalone View
swh/indexer/metadata.py
Show First 20 Lines • Show All 279 Lines • ▼ Show 20 Lines | def run(self, origin_head, policy_update): | ||||
as first argument; ie. not a list of ids as other indexers would. | as first argument; ie. not a list of ids as other indexers would. | ||||
Args: | Args: | ||||
origin_head (dict): {str(origin_id): rev_id} | origin_head (dict): {str(origin_id): rev_id} | ||||
keys `origin_id` and `revision_id`, which is the result | keys `origin_id` and `revision_id`, which is the result | ||||
of OriginHeadIndexer. | of OriginHeadIndexer. | ||||
policy_update (str): `'ignore-dups'` or `'update-dups'` | policy_update (str): `'ignore-dups'` or `'update-dups'` | ||||
""" | """ | ||||
origin_head_map = {int(origin_id): hashutil.hash_to_bytes(rev_id) | origin_head_map = {origin_id: hashutil.hash_to_bytes(rev_id) | ||||
for (origin_id, rev_id) in origin_head.items()} | for (origin_id, rev_id) in origin_head.items()} | ||||
# Fix up the argument order. revisions_metadata has to be the | # Fix up the argument order. revisions_metadata has to be the | ||||
# first argument because of celery.chain; the next line calls | # first argument because of celery.chain; the next line calls | ||||
# run() with the usual order, ie. origin ids first. | # run() with the usual order, ie. origin ids first. | ||||
return super().run(ids=list(origin_head_map), | return super().run(ids=list(origin_head_map), | ||||
policy_update=policy_update, | policy_update=policy_update, | ||||
parse_ids=False, | parse_ids=False, | ||||
origin_head_map=origin_head_map) | origin_head_map=origin_head_map) | ||||
def index(self, origin, *, origin_head_map): | def index(self, origin, *, origin_head_map): | ||||
# Get the last revision of the origin. | # Get the last revision of the origin. | ||||
revision_id = origin_head_map[origin['id']] | revision_id = origin_head_map[str(origin['id'])] | ||||
revision_metadata = self.idx_storage \ | revision_metadata = self.idx_storage \ | ||||
.revision_metadata_get([revision_id]) | .revision_metadata_get([revision_id]) | ||||
results = [] | results = [] | ||||
for item in revision_metadata: | for item in revision_metadata: | ||||
assert item['id'] == revision_id | assert item['id'] == revision_id | ||||
# Get the metadata of that revision, and return it | # Get the metadata of that revision, and return it | ||||
Show All 27 Lines |