Changeset View
Standalone View
swh/storage/cassandra/storage.py
Show First 20 Lines • Show All 671 Lines • ▼ Show 20 Lines | ) -> Optional[Dict[Optional[str], int]]: | ||||
return self._cql_runner.snapshot_count_branches(snapshot_id) | return self._cql_runner.snapshot_count_branches(snapshot_id) | ||||
def snapshot_get_branches( | def snapshot_get_branches( | ||||
self, | self, | ||||
snapshot_id: Sha1Git, | snapshot_id: Sha1Git, | ||||
branches_from: bytes = b"", | branches_from: bytes = b"", | ||||
branches_count: int = 1000, | branches_count: int = 1000, | ||||
target_types: Optional[List[str]] = None, | target_types: Optional[List[str]] = None, | ||||
branches_name_pattern: Optional[str] = None, | |||||
) -> Optional[PartialBranches]: | ) -> Optional[PartialBranches]: | ||||
if self._cql_runner.snapshot_missing([snapshot_id]): | if self._cql_runner.snapshot_missing([snapshot_id]): | ||||
# Makes sure we don't fetch branches for a snapshot that is | # Makes sure we don't fetch branches for a snapshot that is | ||||
# being added. | # being added. | ||||
return None | return None | ||||
branches: List = [] | branches: List = [] | ||||
while len(branches) < branches_count + 1: | while len(branches) < branches_count + 1: | ||||
new_branches = list( | new_branches = list( | ||||
self._cql_runner.snapshot_branch_get( | self._cql_runner.snapshot_branch_get( | ||||
snapshot_id, branches_from, branches_count + 1 | snapshot_id, branches_from, branches_count + 1 | ||||
vlorentz: `b"\xff"` is not the last possible branch name, there could be branches named `b"\xff\xff"` | |||||
Done Inline ActionsI guess I am forced to use two different CQL queries then, one with WHERE name < prefix and the other with WHERE name > prefix. I wanted to modify the less code as possible but looks like it is not possible to use a single query. anlambert: I guess I am forced to use two different CQL queries then, one with `WHERE name < prefix` and… | |||||
) | ) | ||||
) | ) | ||||
if not new_branches: | if not new_branches: | ||||
break | break | ||||
Not Done Inline ActionsI'm confused. How does that return branches that are after the prefix? vlorentz: I'm confused. How does that return branches that are after the prefix? | |||||
Done Inline ActionsThe snapshot branches CQL query have been updated to scan branches inside a range [from_branch_name, to_branch_name[. anlambert: The snapshot branches CQL query have been updated to scan branches inside a range `… | |||||
branches_from = new_branches[-1].name | branches_from = new_branches[-1].name | ||||
new_branches_filtered = new_branches | new_branches_filtered = new_branches | ||||
# Filter by target_type | # Filter by target_type | ||||
if target_types: | if target_types: | ||||
new_branches_filtered = [ | new_branches_filtered = [ | ||||
branch | branch | ||||
for branch in new_branches_filtered | for branch in new_branches_filtered | ||||
if branch.target is not None and branch.target_type in target_types | if branch.target is not None and branch.target_type in target_types | ||||
] | ] | ||||
# Filter by branches_name_pattern | |||||
if branches_name_pattern: | |||||
pattern = re.compile(branches_name_pattern) | |||||
new_branches_filtered = [ | |||||
branch | |||||
for branch in new_branches_filtered | |||||
if branch.name is not None | |||||
and pattern.search(branch.name.decode("utf-8")) | |||||
] | |||||
branches.extend(new_branches_filtered) | branches.extend(new_branches_filtered) | ||||
if len(new_branches) < branches_count + 1: | if len(new_branches) < branches_count + 1: | ||||
break | break | ||||
Not Done Inline Actionswould be easier by setting a variable before filtering on branch_name_include_pattern vlorentz: would be easier by setting a variable before filtering on `branch_name_include_pattern` | |||||
Done Inline Actionsyou mean for the right part of the if condition ? anlambert: you mean for the right part of the if condition ? | |||||
if len(branches) > branches_count: | if len(branches) > branches_count: | ||||
last_branch = branches.pop(-1).name | last_branch = branches.pop(-1).name | ||||
else: | else: | ||||
last_branch = None | last_branch = None | ||||
return PartialBranches( | return PartialBranches( | ||||
id=snapshot_id, | id=snapshot_id, | ||||
branches={ | branches={ | ||||
Not Done Inline Actionswhat does this do? vlorentz: what does this do? | |||||
Done Inline ActionsIt updates the names range to scan snapshot branches:
anlambert: It updates the names range to scan snapshot branches:
- when all branches before the prefix… | |||||
branch.name: None | branch.name: None | ||||
if branch.target is None | if branch.target is None | ||||
else SnapshotBranch( | else SnapshotBranch( | ||||
target=branch.target, target_type=TargetType(branch.target_type) | target=branch.target, target_type=TargetType(branch.target_type) | ||||
) | ) | ||||
for branch in branches | for branch in branches | ||||
}, | }, | ||||
next_branch=last_branch, | next_branch=last_branch, | ||||
▲ Show 20 Lines • Show All 595 Lines • Show Last 20 Lines |
b"\xff" is not the last possible branch name, there could be branches named b"\xff\xff"