diff --git a/swh/storage/cassandra/cql.py b/swh/storage/cassandra/cql.py --- a/swh/storage/cassandra/cql.py +++ b/swh/storage/cassandra/cql.py @@ -556,12 +556,6 @@ def snapshot_add_one(self, snapshot: SnapshotRow, *, statement) -> None: self._add_one(statement, snapshot) - @_prepared_select_statement(SnapshotRow, "WHERE id = ?") - def snapshot_get(self, snapshot_id: Sha1Git, *, statement) -> ResultSet: - return map( - SnapshotRow.from_dict, self._execute_with_retries(statement, [snapshot_id]) - ) - @_prepared_select_statement(SnapshotRow, "WHERE token(id) > ? LIMIT 1") def snapshot_get_random(self, *, statement) -> Optional[SnapshotRow]: return self._get_random_row(SnapshotRow, statement) diff --git a/swh/storage/cassandra/storage.py b/swh/storage/cassandra/storage.py --- a/swh/storage/cassandra/storage.py +++ b/swh/storage/cassandra/storage.py @@ -646,16 +646,6 @@ "next_branch": d["next_branch"], } - def snapshot_get_by_origin_visit( - self, origin: str, visit: int - ) -> Optional[Dict[str, Any]]: - visit_status = self.origin_visit_status_get_latest( - origin, visit, require_snapshot=True - ) - if visit_status and visit_status.snapshot: - return self.snapshot_get(visit_status.snapshot) - return None - def snapshot_count_branches( self, snapshot_id: Sha1Git ) -> Optional[Dict[Optional[str], int]]: diff --git a/swh/storage/db.py b/swh/storage/db.py --- a/swh/storage/db.py +++ b/swh/storage/db.py @@ -262,23 +262,6 @@ yield from cur - def snapshot_get_by_origin_visit(self, origin_url, visit_id, cur=None): - cur = self._cursor(cur) - query = """\ - SELECT ovs.snapshot - FROM origin_visit ov - INNER JOIN origin o ON o.id = ov.origin - INNER JOIN origin_visit_status ovs - ON ov.origin = ovs.origin AND ov.visit = ovs.visit - WHERE o.url=%s AND ov.visit=%s - ORDER BY ovs.date DESC LIMIT 1 - """ - - cur.execute(query, (origin_url, visit_id)) - ret = cur.fetchone() - if ret: - return ret[0] - def snapshot_get_random(self, cur=None): return self._get_random_row_from_table("snapshot", ["id"], "id", cur) diff --git a/swh/storage/in_memory.py b/swh/storage/in_memory.py --- a/swh/storage/in_memory.py +++ b/swh/storage/in_memory.py @@ -515,25 +515,6 @@ "next_branch": d["next_branch"], } - def snapshot_get_by_origin_visit( - self, origin: str, visit: int - ) -> Optional[Dict[str, Any]]: - origin_url = self._get_origin_url(origin) - if not origin_url: - return None - - if origin_url not in self._origins or visit > len( - self._origin_visits[origin_url] - ): - return None - - visit_d = self._origin_visit_get_updated(origin_url, visit) - snapshot_id = visit_d["snapshot"] - if snapshot_id: - return self.snapshot_get(snapshot_id) - else: - return None - def snapshot_count_branches( self, snapshot_id: Sha1Git ) -> Optional[Dict[Optional[str], int]]: diff --git a/swh/storage/interface.py b/swh/storage/interface.py --- a/swh/storage/interface.py +++ b/swh/storage/interface.py @@ -683,37 +683,6 @@ """ ... - @remote_api_endpoint("snapshot/by_origin_visit") - def snapshot_get_by_origin_visit( - self, origin: str, visit: int - ) -> Optional[Dict[str, Any]]: - """Get the content, possibly partial, of a snapshot for the given origin visit - - The branches of the snapshot are iterated in the lexicographical - order of their names. - - .. warning:: At most 1000 branches contained in the snapshot will be - returned for performance reasons. In order to browse the whole - set of branches, the method :meth:`snapshot_get_branches` - should be used instead. - - Args: - origin: origin identifier (url) - visit: the visit identifier - - Returns: - dict: None if the snapshot does not exist; - a dict with three keys otherwise: - * **id**: identifier of the snapshot - * **branches**: a dict of branches contained in the snapshot - whose keys are the branches' names. - * **next_branch**: the name of the first branch not returned - or :const:`None` if the snapshot has less than 1000 - branches. - - """ - ... - @remote_api_endpoint("snapshot/count_branches") def snapshot_count_branches( self, snapshot_id: Sha1Git diff --git a/swh/storage/storage.py b/swh/storage/storage.py --- a/swh/storage/storage.py +++ b/swh/storage/storage.py @@ -755,18 +755,6 @@ "next_branch": d["next_branch"], } - @timed - @db_transaction(statement_timeout=2000) - def snapshot_get_by_origin_visit( - self, origin: str, visit: int, db=None, cur=None - ) -> Optional[Dict[str, Any]]: - snapshot_id = db.snapshot_get_by_origin_visit(origin, visit, cur) - - if snapshot_id: - return self.snapshot_get(snapshot_id, db=db, cur=cur) - - return None - @timed @db_transaction(statement_timeout=2000) def snapshot_count_branches( diff --git a/swh/storage/tests/test_storage.py b/swh/storage/tests/test_storage.py --- a/swh/storage/tests/test_storage.py +++ b/swh/storage/tests/test_storage.py @@ -2527,9 +2527,6 @@ by_id = swh_storage.snapshot_get(empty_snapshot.id) assert by_id == {**empty_snapshot_dict, "next_branch": None} - by_ov = swh_storage.snapshot_get_by_origin_visit(origin.url, ov1.visit) - assert by_ov == {**empty_snapshot_dict, "next_branch": None} - ovs1 = OriginVisitStatus.from_dict( { "origin": origin.url, @@ -2574,7 +2571,6 @@ type=sample_data.type_visit1, ) origin_visit1 = swh_storage.origin_visit_add([visit])[0] - visit_id = origin_visit1.visit actual_result = swh_storage.snapshot_add([complete_snapshot]) swh_storage.origin_visit_status_add( @@ -2593,9 +2589,6 @@ by_id = swh_storage.snapshot_get(complete_snapshot.id) assert by_id == {**complete_snapshot_dict, "next_branch": None} - by_ov = swh_storage.snapshot_get_by_origin_visit(origin.url, visit_id) - assert by_ov == {**complete_snapshot_dict, "next_branch": None} - def test_snapshot_add_many(self, swh_storage, sample_data): snapshot, _, complete_snapshot = sample_data.snapshots[:3] @@ -2908,9 +2901,6 @@ by_id = swh_storage.snapshot_get(snapshot.id) assert by_id == expected_snapshot - by_ov = swh_storage.snapshot_get_by_origin_visit(origin.url, ov1.visit) - assert by_ov == expected_snapshot - actual_visit = swh_storage.origin_visit_get_by(origin.url, ov1.visit) assert actual_visit == ov1 @@ -2919,121 +2909,6 @@ ) assert visit_status.snapshot == snapshot.id - def test_snapshot_add_twice__by_origin_visit(self, swh_storage, sample_data): - snapshot = sample_data.snapshot - origin = sample_data.origin - - swh_storage.origin_add([origin]) - ov1 = swh_storage.origin_visit_add( - [ - OriginVisit( - origin=origin.url, - date=sample_data.date_visit1, - type=sample_data.type_visit1, - ) - ] - )[0] - swh_storage.snapshot_add([snapshot]) - date_now2 = now() - - swh_storage.origin_visit_status_add( - [ - OriginVisitStatus( - origin=origin.url, - visit=ov1.visit, - date=date_now2, - status="ongoing", - snapshot=snapshot.id, - ) - ] - ) - - expected_snapshot = {**snapshot.to_dict(), "next_branch": None} - - by_ov1 = swh_storage.snapshot_get_by_origin_visit(origin.url, ov1.visit) - assert by_ov1 == expected_snapshot - - ov2 = swh_storage.origin_visit_add( - [ - OriginVisit( - origin=origin.url, - date=sample_data.date_visit2, - type=sample_data.type_visit2, - ) - ] - )[0] - - date_now4 = now() - swh_storage.origin_visit_status_add( - [ - OriginVisitStatus( - origin=origin.url, - visit=ov2.visit, - date=date_now4, - status="ongoing", - snapshot=snapshot.id, - ) - ] - ) - - by_ov2 = swh_storage.snapshot_get_by_origin_visit(origin.url, ov2.visit) - assert by_ov2 == expected_snapshot - - ovs1 = OriginVisitStatus.from_dict( - { - "origin": origin.url, - "date": sample_data.date_visit1, - "visit": ov1.visit, - "status": "created", - "metadata": None, - "snapshot": None, - } - ) - ovs2 = OriginVisitStatus.from_dict( - { - "origin": origin.url, - "date": date_now2, - "visit": ov1.visit, - "status": "ongoing", - "metadata": None, - "snapshot": snapshot.id, - } - ) - ovs3 = OriginVisitStatus.from_dict( - { - "origin": origin.url, - "date": sample_data.date_visit2, - "visit": ov2.visit, - "status": "created", - "metadata": None, - "snapshot": None, - } - ) - ovs4 = OriginVisitStatus.from_dict( - { - "origin": origin.url, - "date": date_now4, - "visit": ov2.visit, - "status": "ongoing", - "metadata": None, - "snapshot": snapshot.id, - } - ) - actual_objects = list(swh_storage.journal_writer.journal.objects) - expected_objects = [ - ("origin", origin), - ("origin_visit", ov1), - ("origin_visit_status", ovs1), - ("snapshot", snapshot), - ("origin_visit_status", ovs2), - ("origin_visit", ov2), - ("origin_visit_status", ovs3), - ("origin_visit_status", ovs4), - ] - - for obj in expected_objects: - assert obj in actual_objects - def test_snapshot_get_random(self, swh_storage, sample_data): snapshot, empty_snapshot, complete_snapshot = sample_data.snapshots[:3] swh_storage.snapshot_add([snapshot, empty_snapshot, complete_snapshot])