Skip to content

Commit

Permalink
MNT: only cache FilestoreBackend._gather_progeny during .search
Browse files Browse the repository at this point in the history
  • Loading branch information
shilorigins committed Nov 21, 2024
1 parent b54d3dc commit 452291f
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions superscore/backends/filestore.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ def search(self, *search_terms: SearchTermType) -> Generator[Entry, None, None]:
Keys are attributes on `Entry` subclasses, or special keywords.
Values can be a single value or a tuple of values depending on operator.
"""
cached_progeny = cache(self._gather_progeny)
with self._load_and_store_context() as db:
for entry in db.values():
conditions = []
Expand All @@ -294,7 +295,7 @@ def search(self, *search_terms: SearchTermType) -> Generator[Entry, None, None]:
if attr == "entry_type":
conditions.append(isinstance(entry, target))
elif attr == "ancestor":
conditions.append(entry.uuid in self._gather_progeny(target))
conditions.append(entry.uuid in cached_progeny(target))
else:
try:
# check entry attribute by name
Expand All @@ -305,7 +306,6 @@ def search(self, *search_terms: SearchTermType) -> Generator[Entry, None, None]:
if all(conditions):
yield entry

@cache
def _gather_progeny(self, ancestor: UUID) -> Container[UUID]:
"""
Finds all entries accessible from ancestor, and returns their UUIDs. This
Expand Down

0 comments on commit 452291f

Please sign in to comment.