Skip to content

Commit

Permalink
no exists-caching
Browse files Browse the repository at this point in the history
  • Loading branch information
johnkerl committed Jul 15, 2022
1 parent d35e86b commit 7971580
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 24 deletions.
11 changes: 1 addition & 10 deletions apis/python/src/tiledbsc/soma.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,7 @@ def __init__(
ctx=ctx,
)

# obs_uri = self._get_child_uri("obs") # See comments in that function
# var_uri = self._get_child_uri("var")
# X_uri = self._get_child_uri("X")
# obsm_uri = self._get_child_uri("obsm")
# varm_uri = self._get_child_uri("varm")
# obsp_uri = self._get_child_uri("obsp")
# varp_uri = self._get_child_uri("varp")
# raw_uri = self._get_child_uri("raw")
# uns_uri = self._get_child_uri("uns")

# TODO: COMMENT
member_names = ["obs", "var", "X", "obsm", "varm", "obsp", "varp", "raw", "uns"]
child_uris = self._get_child_uris(member_names) # See comments in that function

Expand Down
4 changes: 1 addition & 3 deletions apis/python/src/tiledbsc/soma_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def __init__(
ctx=ctx,
)

self._somas = None
self._somas = {}

# ----------------------------------------------------------------
def __repr__(self) -> str:
Expand Down Expand Up @@ -125,8 +125,6 @@ def __iter__(self) -> Iterator[SOMA]:
"""
Implements `for soma in soco: ...`
"""
if self._somas is None:
self._somas = {}
for name, uri in self._get_member_names_to_uris().items():
if name not in self._somas:
self._somas[name] = SOMA(uri=uri, name=name, parent=self, ctx=self._ctx)
Expand Down
11 changes: 2 additions & 9 deletions apis/python/src/tiledbsc/tiledb_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ class TileDBGroup(TileDBObject):
Wraps groups from TileDB-Py by retaining a URI, options, etc.
"""

_cached_exists: Optional[bool]
_cached_member_names_to_uris: Optional[Dict[str, str]]

def __init__(
Expand All @@ -33,7 +32,6 @@ def __init__(
See the TileDBObject constructor.
"""
super().__init__(uri, name, parent=parent, soma_options=soma_options, ctx=ctx)
self._cached_exists = None
self._cached_member_names_to_uris = None

def exists(self) -> bool:
Expand All @@ -43,11 +41,8 @@ def exists(self) -> bool:
SOMA has been populated but doesn't have this member (e.g. not all SOMAs have a `varp`).
"""
# TODO: NOTE WHAT IF VFS.DELETE AFTER INSTANTIATION
if self._cached_exists is None:
self._cached_exists = bool(
tiledb.object_type(self.uri, ctx=self._ctx) == "group"
)
return self._cached_exists
# TODO: NON-CACHEABLE AND WHY
return tiledb.object_type(self.uri, ctx=self._ctx) == "group"

def create_unless_exists(self) -> None:
"""
Expand Down Expand Up @@ -89,7 +84,6 @@ def _open(self, mode: str = "r") -> tiledb.Group:
This is just a convenience wrapper around tiledb group-open.
It works asa `with self._open() as G:` as well as `G = self._open(); ...; G.close()`.
"""
print("OPEN", self.uri)
assert mode in ("r", "w")
if mode == "r" and not self.exists():
raise Exception(f"Does not exist: {self.uri}")
Expand Down Expand Up @@ -236,7 +230,6 @@ def _get_member_names_to_uris(self) -> Dict[str, str]:
if self._cached_member_names_to_uris is None:
with self._open("r") as G:
self._cached_member_names_to_uris = {obj.name: obj.uri for obj in G}
print("GMN2U", self.uri)
return self._cached_member_names_to_uris

def show_metadata(self, recursively: bool = True, indent: str = "") -> None:
Expand Down
2 changes: 0 additions & 2 deletions apis/python/tools/ingestor
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,6 @@ def ingest_one(
f"Already exists; replacing: {output_path}"
)
shutil.rmtree(output_path) # Overwrite
# TODO: COMMENT
soma = tiledbsc.SOMA(uri=output_path, soma_options=soma_options)
else:
raise Exception(
"Internal coding error in --ifexists handling.", ifexists, "<"
Expand Down

0 comments on commit 7971580

Please sign in to comment.