Changeset View
Changeset View
Standalone View
Standalone View
swh/storage/postgresql/storage.py
Show First 20 Lines • Show All 773 Lines • ▼ Show 20 Lines | ) -> Optional[PartialBranches]: | ||||
branches = {} | branches = {} | ||||
next_branch = None | next_branch = None | ||||
fetched_branches = list( | fetched_branches = list( | ||||
db.snapshot_get_by_id( | db.snapshot_get_by_id( | ||||
snapshot_id, | snapshot_id, | ||||
branches_from=branches_from, | branches_from=branches_from, | ||||
branches_count=branches_count + 1, | # the underlying SQL query can be quite expensive to execute for small | ||||
# branches_count value, so we ensure a minimum branches limit of 10 for | |||||
# optimal performances | |||||
ardumont: for pagination consistency's sake? | |||||
Done Inline ActionsWhat do you mean ? anlambert: What do you mean ? | |||||
Not Done Inline Actionsnvm ardumont: nvm | |||||
branches_count=max(branches_count + 1, 10), | |||||
target_types=target_types, | target_types=target_types, | ||||
cur=cur, | cur=cur, | ||||
) | ) | ||||
) | ) | ||||
for row in fetched_branches[:branches_count]: | for row in fetched_branches[:branches_count]: | ||||
branch_d = dict(zip(db.snapshot_get_cols, row)) | branch_d = dict(zip(db.snapshot_get_cols, row)) | ||||
del branch_d["snapshot_id"] | del branch_d["snapshot_id"] | ||||
name = branch_d.pop("name") | name = branch_d.pop("name") | ||||
if branch_d["target"] is None and branch_d["target_type"] is None: | if branch_d["target"] is None and branch_d["target_type"] is None: | ||||
branch = None | branch = None | ||||
else: | else: | ||||
assert branch_d["target_type"] is not None | assert branch_d["target_type"] is not None | ||||
branch = SnapshotBranch( | branch = SnapshotBranch( | ||||
target=branch_d["target"], | target=branch_d["target"], | ||||
target_type=TargetType(branch_d["target_type"]), | target_type=TargetType(branch_d["target_type"]), | ||||
) | ) | ||||
branches[name] = branch | branches[name] = branch | ||||
if len(fetched_branches) > branches_count: | if len(fetched_branches) > branches_count: | ||||
next_branch = dict(zip(db.snapshot_get_cols, fetched_branches[-1]))["name"] | next_branch = dict( | ||||
zip(db.snapshot_get_cols, fetched_branches[branches_count]) | |||||
)["name"] | |||||
if branches: | if branches: | ||||
return PartialBranches( | return PartialBranches( | ||||
id=snapshot_id, branches=branches, next_branch=next_branch, | id=snapshot_id, branches=branches, next_branch=next_branch, | ||||
) | ) | ||||
return None | return None | ||||
▲ Show 20 Lines • Show All 588 Lines • Show Last 20 Lines |
for pagination consistency's sake?