Changeset View
Changeset View
Standalone View
Standalone View
swh/storage/cassandra/cql.py
Show First 20 Lines • Show All 974 Lines • ▼ Show 20 Lines | def origin_visit_status_get_latest( | ||||
self, origin: str, visit: int, | self, origin: str, visit: int, | ||||
) -> Optional[OriginVisitStatusRow]: | ) -> Optional[OriginVisitStatusRow]: | ||||
"""Given an origin visit id, return its latest origin_visit_status | """Given an origin visit id, return its latest origin_visit_status | ||||
""" | """ | ||||
return next(self.origin_visit_status_get(origin, visit), None) | return next(self.origin_visit_status_get(origin, visit), None) | ||||
@_prepared_select_statement( | @_prepared_select_statement( | ||||
OriginVisitStatusRow, "WHERE origin = ? AND visit = ? ORDER BY date DESC" | OriginVisitStatusRow, | ||||
# 'visit DESC,' is optional with Cassandra 4, but ScyllaDB needs it | |||||
"WHERE origin = ? AND visit = ? ORDER BY visit DESC, date DESC", | |||||
) | ) | ||||
def origin_visit_status_get( | def origin_visit_status_get( | ||||
self, origin: str, visit: int, *, statement, | self, origin: str, visit: int, *, statement, | ||||
) -> Iterator[OriginVisitStatusRow]: | ) -> Iterator[OriginVisitStatusRow]: | ||||
"""Return all origin visit statuses for a given visit | """Return all origin visit statuses for a given visit | ||||
""" | """ | ||||
return map( | return map( | ||||
▲ Show 20 Lines • Show All 62 Lines • ▼ Show 20 Lines | ) -> Iterable[RawExtrinsicMetadataRow]: | ||||
RawExtrinsicMetadataRow.from_dict, | RawExtrinsicMetadataRow.from_dict, | ||||
self._execute_with_retries( | self._execute_with_retries( | ||||
statement, [target, authority_url, after, authority_type] | statement, [target, authority_url, after, authority_type] | ||||
), | ), | ||||
) | ) | ||||
@_prepared_select_statement( | @_prepared_select_statement( | ||||
RawExtrinsicMetadataRow, | RawExtrinsicMetadataRow, | ||||
"WHERE target=? AND authority_type=? AND authority_url=? " | # This is equivalent to: | ||||
"AND (discovery_date, id) > (?, ?)", | # WHERE target=? AND authority_type = ? AND authority_url = ? " | ||||
# AND (discovery_date, id) > (?, ?)" | |||||
# but it needs to be written this way to work with ScyllaDB. | |||||
"WHERE target=? AND (authority_type, authority_url) <= (?, ?) " | |||||
"AND (authority_type, authority_url, discovery_date, id) > (?, ?, ?, ?)", | |||||
) | ) | ||||
def raw_extrinsic_metadata_get_after_date_and_id( | def raw_extrinsic_metadata_get_after_date_and_id( | ||||
self, | self, | ||||
target: str, | target: str, | ||||
authority_type: str, | authority_type: str, | ||||
authority_url: str, | authority_url: str, | ||||
after_date: datetime.datetime, | after_date: datetime.datetime, | ||||
after_id: bytes, | after_id: bytes, | ||||
*, | *, | ||||
statement, | statement, | ||||
) -> Iterable[RawExtrinsicMetadataRow]: | ) -> Iterable[RawExtrinsicMetadataRow]: | ||||
return map( | return map( | ||||
RawExtrinsicMetadataRow.from_dict, | RawExtrinsicMetadataRow.from_dict, | ||||
self._execute_with_retries( | self._execute_with_retries( | ||||
statement, | statement, | ||||
[target, authority_type, authority_url, after_date, after_id,], | [ | ||||
target, | |||||
authority_type, | |||||
authority_url, | |||||
authority_type, | |||||
authority_url, | |||||
after_date, | |||||
after_id, | |||||
], | |||||
), | ), | ||||
) | ) | ||||
@_prepared_select_statement( | @_prepared_select_statement( | ||||
RawExtrinsicMetadataRow, | RawExtrinsicMetadataRow, | ||||
"WHERE target=? AND authority_url=? AND authority_type=?", | "WHERE target=? AND authority_url=? AND authority_type=?", | ||||
) | ) | ||||
def raw_extrinsic_metadata_get( | def raw_extrinsic_metadata_get( | ||||
▲ Show 20 Lines • Show All 118 Lines • Show Last 20 Lines |