Staging instance, all changes can be removed at any time

Skip to content

Interface: Add a function to get a snapshot branch by its name

Jayesh requested to merge jayeshv/swh-storage:snapshot-branch-by-name into master

Return a result object with the first branch with a non alias target and the aliases_followed list

Getting a snapshot branch by filtering by required name is slow in Postgres. This query offers a better performance.

This is a requirement in GraphQL to add head branch as an attriburte in the Snapshot object.

performance with Postgres backend

In [26]: a=time.time(); print(storage.snapshot_branch_get_by_name(snapshot_id=b'\x0bf\xd9\x890V\xda\\\xc3\x04\xf6\xf9\xbf\x94\xd2\xe3\x8d\x8b\xe1\xdd', branch_name=b'HEAD')); print(time.time(
    ...: )-a)
{'branch_found': True, 'target': SnapshotBranch(target=hash_to_bytes('e54de2a98bb6667a109594c49439346b8e9beff1'), target_type=TargetType.REVISION), 'aliases_followed': [b'HEAD', b'refs/heads/master']}
0.0817255973815918

In [27]: a=time.time(); print(storage.snapshot_get_branches(snapshot_id=b'\x0bf\xd9\x890V\xda\\\xc3\x04\xf6\xf9\xbf\x94\xd2\xe3\x8d\x8b\xe1\xdd', branches_from='HEAD', branches_count=1)); pri
    ...: nt(time.time()-a)
{'id': b'\x0bf\xd9\x890V\xda\\\xc3\x04\xf6\xf9\xbf\x94\xd2\xe3\x8d\x8b\xe1\xdd', 'branches': {b'HEAD': SnapshotBranch(target=hash_to_bytes('726566732f68656164732f6d6173746572'), target_type=TargetType.ALIAS)}, 'next_branch': b'refs/heads/master'}
0.2987356185913086
Edited by Jayesh

Merge request reports

Loading