Skip to content

Commit

Permalink
minro update to structured_data
Browse files Browse the repository at this point in the history
  • Loading branch information
dmichaels-harvard committed Mar 7, 2024
1 parent 8cff942 commit 3a16630
Showing 1 changed file with 35 additions and 2 deletions.
37 changes: 35 additions & 2 deletions dcicutils/structured_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,18 @@ def ref_cache_hit_count(self) -> int:
def ref_lookup_count(self) -> int:
return self.portal.ref_lookup_count if self.portal else -1

@property
def ref_lookup_found_count(self) -> int:
return self.portal.ref_lookup_found_count if self.portal else -1

@property
def ref_lookup_notfound_count(self) -> int:
return self.portal.ref_lookup_notfound_count if self.portal else -1

@property
def ref_lookup_error_count(self) -> int:
return self.portal.ref_lookup_error_count if self.portal else -1

def _note_warning(self, item: Optional[Union[dict, List[dict]]], group: str) -> None:
self._note_issue(self._warnings, item, group)

Expand Down Expand Up @@ -695,6 +707,9 @@ def __init__(self,
self._ref_cache = {}
self._ref_cache_hit_count = 0
self._ref_lookup_count = 0
self._ref_lookup_found_count = 0
self._ref_lookup_notfound_count = 0
self._ref_lookup_error_count = 0

@lru_cache(maxsize=8092)
def get_metadata_cache(self, object_name: str) -> Optional[dict]:
Expand All @@ -703,8 +718,14 @@ def get_metadata_cache(self, object_name: str) -> Optional[dict]:
def get_metadata_nocache(self, object_name: str) -> Optional[dict]:
try:
self._ref_lookup_count += 1
return super().get_metadata(object_name)
except Exception:
result = super().get_metadata(object_name)
self._ref_lookup_found_count += 1
return result
except Exception as e:
if "HTTPNotFound" in str(e):
self._ref_lookup_notfound_count += 1
else:
self._ref_lookup_error_count += 1
return None

@lru_cache(maxsize=256)
Expand Down Expand Up @@ -813,6 +834,18 @@ def ref_cache_hit_count(self) -> int:
def ref_lookup_count(self) -> int:
return self._ref_lookup_count

@property
def ref_lookup_found_count(self) -> int:
return self._ref_lookup_found_count

@property
def ref_lookup_notfound_count(self) -> int:
return self._ref_lookup_notfound_count

@property
def ref_lookup_error_count(self) -> int:
return self._ref_lookup_error_count

@staticmethod
def create_for_testing(arg: Optional[Union[str, bool, List[dict], dict, Callable]] = None,
schemas: Optional[List[dict]] = None) -> Portal:
Expand Down

0 comments on commit 3a16630

Please sign in to comment.