Changeset View
Changeset View
Standalone View
Standalone View
swh/provenance/provenance.py
Show First 20 Lines • Show All 103 Lines • ▼ Show 20 Lines | class ProvenanceInterface(Protocol): | ||||
) -> None: | ) -> None: | ||||
... | ... | ||||
def revision_visited(self, revision: RevisionEntry) -> bool: | def revision_visited(self, revision: RevisionEntry) -> bool: | ||||
... | ... | ||||
class DatetimeCache(TypedDict): | class DatetimeCache(TypedDict): | ||||
data: Dict[Sha1Git, datetime] | data: Dict[Sha1Git, Optional[datetime]] | ||||
added: Set[Sha1Git] | added: Set[Sha1Git] | ||||
class OriginCache(TypedDict): | class OriginCache(TypedDict): | ||||
data: Dict[Sha1Git, str] | data: Dict[Sha1Git, str] | ||||
added: Set[Sha1Git] | added: Set[Sha1Git] | ||||
▲ Show 20 Lines • Show All 124 Lines • ▼ Show 20 Lines | class ProvenanceBackend: | ||||
def get_dates( | def get_dates( | ||||
self, entity: Literal["content", "revision", "directory"], ids: List[Sha1Git] | self, entity: Literal["content", "revision", "directory"], ids: List[Sha1Git] | ||||
) -> Dict[Sha1Git, datetime]: | ) -> Dict[Sha1Git, datetime]: | ||||
cache = self.cache[entity] | cache = self.cache[entity] | ||||
missing_ids = set(id for id in ids if id not in cache) | missing_ids = set(id for id in ids if id not in cache) | ||||
if missing_ids: | if missing_ids: | ||||
cache["data"].update(self.storage.get_dates(entity, list(missing_ids))) | cache["data"].update(self.storage.get_dates(entity, list(missing_ids))) | ||||
return {sha1: cache["data"][sha1] for sha1 in ids if sha1 in cache["data"]} | return { | ||||
sha1: date | |||||
for sha1, date in cache["data"].items() | |||||
if sha1 in ids and date is not None | |||||
} | |||||
douardda: I don't see the point of looping on the whole cache here rather than the input list of sha1s. | |||||
Done Inline ActionsBecause cache now hold Optional[datetime] as values and this method return datetime. So this is mainly to please mypy aeviso: Because cache now hold `Optional[datetime]` as values and this method return `datetime`. So… | |||||
Done Inline ActionsBut does my proposal code makes mypy unhappy? douardda: But does my proposal code makes mypy unhappy? | |||||
Done Inline Actionsmy suggested code douardda: my //suggested// code | |||||
Done Inline ActionsYes, you are making the check against a call to .get(sha1) but adding to the dict the of indexing ([sha1]) operator... mypy won't acknowledge that this results are equal aeviso: Yes, you are making the check against a call to `.get(sha1)` but adding to the dict the of… | |||||
def origin_add(self, origin: OriginEntry) -> None: | def origin_add(self, origin: OriginEntry) -> None: | ||||
self.cache["origin"]["data"][origin.id] = origin.url | self.cache["origin"]["data"][origin.id] = origin.url | ||||
self.cache["origin"]["added"].add(origin.id) | self.cache["origin"]["added"].add(origin.id) | ||||
def revision_add(self, revision: RevisionEntry): | def revision_add(self, revision: RevisionEntry): | ||||
# Add current revision to the compact DB | |||||
assert revision.date is not None | |||||
self.cache["revision"]["data"][revision.id] = revision.date | self.cache["revision"]["data"][revision.id] = revision.date | ||||
self.cache["revision"]["added"].add(revision.id) | self.cache["revision"]["added"].add(revision.id) | ||||
def revision_add_before_revision( | def revision_add_before_revision( | ||||
self, relative: RevisionEntry, revision: RevisionEntry | self, relative: RevisionEntry, revision: RevisionEntry | ||||
): | ): | ||||
self.cache["revision_before_revision"].setdefault(revision.id, set()).add( | self.cache["revision_before_revision"].setdefault(revision.id, set()).add( | ||||
relative.id | relative.id | ||||
Show All 37 Lines |
I don't see the point of looping on the whole cache here rather than the input list of sha1s.
why not keep the original implemantation adapted to check for None dates?
like