Skip to content

Commit

Permalink
more caching
Browse files Browse the repository at this point in the history
  • Loading branch information
johnkerl committed Jul 13, 2022
1 parent b424f59 commit d65ea45
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions apis/python/src/tiledbsc/soma_collection.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Iterator, Optional, Sequence, Set, Union
from typing import Dict, Iterator, Optional, Sequence, Set, Union

import tiledb

Expand All @@ -14,6 +14,9 @@ class SOMACollection(TileDBGroup):
Implements a collection of `SOMA` objects.
"""

# XXX COMMENT
_somas: Dict[str, SOMA]

# ----------------------------------------------------------------
def __init__(
self,
Expand Down Expand Up @@ -58,6 +61,8 @@ def __init__(
ctx=ctx,
)

self._somas = None

# ----------------------------------------------------------------
def __repr__(self) -> str:
"""
Expand Down Expand Up @@ -120,8 +125,13 @@ 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():
yield SOMA(uri=uri, name=name, parent=self, ctx=self._ctx)
if name not in self._somas:
self._somas[name] = SOMA(uri=uri, name=name, parent=self, ctx=self._ctx)
yield self._somas[name]


# ----------------------------------------------------------------
def __contains__(self, name: str) -> bool:
Expand Down

0 comments on commit d65ea45

Please sign in to comment.