Skip to content

Commit 1971fcf

Browse files
authored
Cache Manifest files (apache#787)
* cache manifests * update API * small fix * move cache to module level * update signature and check
1 parent b593375 commit 1971fcf

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

pyiceberg/table/snapshots.py

+11-3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import time
2020
from collections import defaultdict
2121
from enum import Enum
22+
from functools import lru_cache
2223
from typing import TYPE_CHECKING, Any, DefaultDict, Dict, Iterable, List, Mapping, Optional
2324

2425
from pydantic import Field, PrivateAttr, model_serializer
@@ -230,6 +231,13 @@ def __eq__(self, other: Any) -> bool:
230231
)
231232

232233

234+
@lru_cache
235+
def _manifests(io: FileIO, manifest_list: str) -> List[ManifestFile]:
236+
"""Return the manifests from the manifest list."""
237+
file = io.new_input(manifest_list)
238+
return list(read_manifest_list(file))
239+
240+
233241
class Snapshot(IcebergBaseModel):
234242
snapshot_id: int = Field(alias="snapshot-id")
235243
parent_snapshot_id: Optional[int] = Field(alias="parent-snapshot-id", default=None)
@@ -250,9 +258,9 @@ def __str__(self) -> str:
250258
return result_str
251259

252260
def manifests(self, io: FileIO) -> List[ManifestFile]:
253-
if self.manifest_list is not None:
254-
file = io.new_input(self.manifest_list)
255-
return list(read_manifest_list(file))
261+
"""Return the manifests for the given snapshot."""
262+
if self.manifest_list:
263+
return _manifests(io, self.manifest_list)
256264
return []
257265

258266

0 commit comments

Comments
 (0)