Changeset View
Standalone View
swh/storage/in_memory.py
Show First 20 Lines • Show All 910 Lines • ▼ Show 20 Lines | def origin_visit_get_by(self, origin: str, visit: int) -> Optional[Dict[str, Any]]: | ||||
return None | return None | ||||
def origin_visit_get_latest( | def origin_visit_get_latest( | ||||
self, | self, | ||||
origin: str, | origin: str, | ||||
type: Optional[str] = None, | type: Optional[str] = None, | ||||
allowed_statuses: Optional[List[str]] = None, | allowed_statuses: Optional[List[str]] = None, | ||||
require_snapshot: bool = False, | require_snapshot: bool = False, | ||||
) -> Optional[Dict[str, Any]]: | ) -> Optional[OriginVisit]: | ||||
ori = self._origins.get(origin) | ori = self._origins.get(origin) | ||||
if not ori: | if not ori: | ||||
return None | return None | ||||
visits = self._origin_visits[ori.url] | |||||
visits = [ | visits = sorted( | ||||
self._origin_visit_get_updated(visit.origin, visit.visit) | self._origin_visits[ori.url], key=lambda v: v.date, reverse=True, | ||||
for visit in visits | ) | ||||
if visit is not None | for visit in visits: | ||||
] | if type is not None and visit.type != type: | ||||
continue | |||||
visit_statuses = self._origin_visit_statuses[origin, visit.visit] | |||||
vlorentz: `visit_statuses` | |||||
Done Inline ActionsIt was too long and i was annoyed by it... ardumont: It was too long and i was annoyed by it... | |||||
Done Inline ActionsI get that, but a abbreviations harm readability vlorentz: I get that, but a abbreviations harm readability | |||||
Done Inline Actionsoh don't worry, i'm gonna change it. You fine about the implementation otherwise? I initially sorted the visit_statuses as well (order by date desc) and kept the list comprehension filterings as here. I changed it because the sorted stanza is a bit hard to read (due to the annoying copy...). ardumont: oh don't worry, i'm gonna change it.
You fine about the implementation otherwise?
I tried to… | |||||
Done Inline Actionsyes, it's fine. vlorentz: yes, it's fine. | |||||
Done Inline ActionsActually, why do we need deepcopies? Aren't they immutable objects now? vlorentz: Actually, why do we need deepcopies? Aren't they immutable objects now? | |||||
Done Inline Actionsafaiui, in-memory's storage implementation regarding its data are lists, aren't they? ardumont: afaiui, in-memory's storage implementation regarding its data are lists, aren't they? | |||||
Done Inline Actionsself._origin_visits = {} self._origin_visit_statuses: Dict[Tuple[str, int], List[OriginVisitStatus]] = {} ardumont: ```
self._origin_visits = {}
self._origin_visit_statuses: Dict[Tuple[str, int]… | |||||
Done Inline Actionsbut yes for origin_visit_statuses here, it's unneeded (left-over from the other implementation i told you about ;) ardumont: but yes for origin_visit_statuses here, it's unneeded (left-over from the other implementation… | |||||
Not Done Inline ActionsIt's also not needed for visits, because we don't modify the list nor return it vlorentz: It's also not needed for visits, because we don't modify the list nor return it | |||||
Done Inline Actionswe sort it, don't that impact it? ardumont: we sort it, don't that impact it? | |||||
Not Done Inline ActionsYou're confusing sorted() with .sort(). The former makes a shallow copy, the latter sorts in-place. vlorentz: You're confusing `sorted()` with `.sort()`. The former makes a shallow copy, the latter sorts… | |||||
Done Inline Actionsindeed, thanks! ardumont: indeed, thanks! | |||||
if type is not None: | |||||
visits = [visit for visit in visits if visit["type"] == type] | |||||
if allowed_statuses is not None: | if allowed_statuses is not None: | ||||
visits = [visit for visit in visits if visit["status"] in allowed_statuses] | visit_statuses = [ | ||||
vs for vs in visit_statuses if vs.status in allowed_statuses | |||||
] | |||||
if require_snapshot: | if require_snapshot: | ||||
visits = [visit for visit in visits if visit["snapshot"]] | visit_statuses = [vs for vs in visit_statuses if vs.snapshot] | ||||
visit = max(visits, key=lambda v: (v["date"], v["visit"]), default=None) | if visit_statuses: # we found visit statuses matching criteria | ||||
if visit is None: | visit_status = max(visit_statuses, key=lambda vs: (vs.date, vs.visit)) | ||||
return None | assert visit.origin == visit_status.origin | ||||
assert visit.visit == visit_status.visit | |||||
return visit | return visit | ||||
return None | |||||
def origin_visit_status_get_latest( | def origin_visit_status_get_latest( | ||||
self, | self, | ||||
origin_url: str, | origin_url: str, | ||||
visit: int, | visit: int, | ||||
allowed_statuses: Optional[List[str]] = None, | allowed_statuses: Optional[List[str]] = None, | ||||
require_snapshot: bool = False, | require_snapshot: bool = False, | ||||
) -> Optional[OriginVisitStatus]: | ) -> Optional[OriginVisitStatus]: | ||||
ori = self._origins.get(origin_url) | ori = self._origins.get(origin_url) | ||||
▲ Show 20 Lines • Show All 259 Lines • Show Last 20 Lines |
visit_statuses