Changeset View
Changeset View
Standalone View
Standalone View
swh/storage/in_memory.py
Show First 20 Lines • Show All 767 Lines • ▼ Show 20 Lines | def origin_visit_update( | ||||
visit = attr.evolve(visit, **updates) | visit = attr.evolve(visit, **updates) | ||||
except (KeyError, TypeError, ValueError) as e: | except (KeyError, TypeError, ValueError) as e: | ||||
raise StorageArgumentException(*e.args) | raise StorageArgumentException(*e.args) | ||||
self.journal_writer.origin_visit_update(visit) | self.journal_writer.origin_visit_update(visit) | ||||
self._origin_visits[origin_url][visit_id-1] = visit | self._origin_visits[origin_url][visit_id-1] = visit | ||||
def origin_visit_upsert(self, visits): | def origin_visit_upsert(self, visits: Iterable[OriginVisit]) -> None: | ||||
for visit in visits: | |||||
if not isinstance(visit['origin'], str): | |||||
raise TypeError("visit['origin'] must be a string, not %r" | |||||
% (visit['origin'],)) | |||||
try: | |||||
visits = [OriginVisit.from_dict(d) for d in visits] | |||||
except (KeyError, TypeError, ValueError) as e: | |||||
raise StorageArgumentException(*e.args) | |||||
self.journal_writer.origin_visit_upsert(visits) | self.journal_writer.origin_visit_upsert(visits) | ||||
for visit in visits: | for visit in visits: | ||||
visit_id = visit.visit | visit_id = visit.visit | ||||
origin_url = visit.origin | origin_url = visit.origin | ||||
try: | try: | ||||
visit = attr.evolve(visit, origin=origin_url) | visit = attr.evolve(visit, origin=origin_url) | ||||
except (KeyError, TypeError, ValueError) as e: | except (KeyError, TypeError, ValueError) as e: | ||||
raise StorageArgumentException(*e.args) | raise StorageArgumentException(*e.args) | ||||
self._objects[(origin_url, visit_id)].append( | self._objects[(origin_url, visit_id)].append( | ||||
('origin_visit', None)) | ('origin_visit', None)) | ||||
if visit_id: | |||||
while len(self._origin_visits[origin_url]) <= visit_id: | while len(self._origin_visits[origin_url]) <= visit_id: | ||||
self._origin_visits[origin_url].append(None) | self._origin_visits[origin_url].append(None) | ||||
self._origin_visits[origin_url][visit_id-1] = visit | self._origin_visits[origin_url][visit_id-1] = visit | ||||
def _convert_visit(self, visit): | def _convert_visit(self, visit): | ||||
if visit is None: | if visit is None: | ||||
return | return | ||||
visit = visit.to_dict() | visit = visit.to_dict() | ||||
return visit | return visit | ||||
▲ Show 20 Lines • Show All 199 Lines • Show Last 20 Lines |