Skip to content

Commit

Permalink
move cache to module level
Browse files Browse the repository at this point in the history
  • Loading branch information
chinmay-bhat committed Jun 10, 2024
1 parent afbf031 commit af6924d
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions pyiceberg/table/snapshots.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,15 @@ def __eq__(self, other: Any) -> bool:
)


@lru_cache
def _manifests(io: FileIO, manifest_list: Optional[str]) -> List[ManifestFile]:
"""Return the manifests from the manifest list."""
if manifest_list not in (None, ""):
file = io.new_input(manifest_list) # type: ignore
return list(read_manifest_list(file))
return []


class Snapshot(IcebergBaseModel):
snapshot_id: int = Field(alias="snapshot-id")
parent_snapshot_id: Optional[int] = Field(alias="parent-snapshot-id", default=None)
Expand All @@ -248,18 +257,9 @@ def __str__(self) -> str:
result_str = f"{operation}id={self.snapshot_id}{parent_id}{schema_id}"
return result_str

@staticmethod
@lru_cache
def _manifests(io: FileIO, manifest_list: Optional[str]) -> List[ManifestFile]:
"""Return the manifests for the given snapshot."""
if manifest_list not in (None, ""):
file = io.new_input(manifest_list) # type: ignore
return list(read_manifest_list(file))
return []

def manifests(self, io: FileIO) -> List[ManifestFile]:
"""Return the manifests for the given snapshot."""
return Snapshot._manifests(io, self.manifest_list)
return _manifests(io, self.manifest_list)


class MetadataLogEntry(IcebergBaseModel):
Expand Down

0 comments on commit af6924d

Please sign in to comment.