Skip to content

Commit a98e036

Browse files
committed
fix: simplify sample info cache and remove unused variable references in radionuclides.py
1 parent 8a6213e commit a98e036

1 file changed

Lines changed: 6 additions & 25 deletions

File tree

transfers/radionuclides.py

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -55,25 +55,23 @@ class RadionuclidesTransferer(Transferer):
5555
def __init__(self, *args, batch_size: int = 1000, **kwargs):
5656
super().__init__(*args, **kwargs)
5757
self.batch_size = batch_size
58-
# Cache: legacy UUID -> (Integer id, thing_id)
59-
self._sample_info_cache: dict[UUID, tuple[int, int]] = {}
58+
# Cache: legacy UUID -> Integer chemistry_sample_info_id
59+
self._sample_info_cache: dict[UUID, int] = {}
6060
self._build_sample_info_cache()
6161

6262
def _build_sample_info_cache(self) -> None:
63-
"""Build cache of nma_sample_pt_id -> (id, thing_id) for FK lookups."""
63+
"""Build cache of nma_sample_pt_id -> chemistry_sample_info_id for FK lookups."""
6464
with session_ctx() as session:
6565
sample_infos = (
6666
session.query(
6767
NMA_Chemistry_SampleInfo.nma_sample_pt_id,
6868
NMA_Chemistry_SampleInfo.id,
69-
NMA_Chemistry_SampleInfo.thing_id,
7069
)
7170
.filter(NMA_Chemistry_SampleInfo.nma_sample_pt_id.isnot(None))
7271
.all()
7372
)
7473
self._sample_info_cache = {
75-
nma_sample_pt_id: (csi_id, thing_id)
76-
for nma_sample_pt_id, csi_id, thing_id in sample_infos
74+
nma_sample_pt_id: csi_id for nma_sample_pt_id, csi_id in sample_infos
7775
}
7876
logger.info(
7977
f"Built ChemistrySampleInfo cache with {len(self._sample_info_cache)} entries"
@@ -105,7 +103,6 @@ def _filter_to_valid_sample_infos(self, df: pd.DataFrame) -> pd.DataFrame:
105103
def _transfer_hook(self, session: Session) -> None:
106104
row_dicts = []
107105
skipped_global_id = 0
108-
skipped_thing_id = 0
109106
for row in self.cleaned_df.to_dict("records"):
110107
row_dict = self._row_dict(row)
111108
if row_dict is None:
@@ -117,13 +114,6 @@ def _transfer_hook(self, session: Session) -> None:
117114
row_dict.get("nma_SamplePtID"),
118115
)
119116
continue
120-
if row_dict.get("thing_id") is None:
121-
skipped_thing_id += 1
122-
logger.warning(
123-
"Skipping Radionuclides nma_SamplePtID=%s - Thing not found",
124-
row_dict.get("nma_SamplePtID"),
125-
)
126-
continue
127117
if row_dict.get("chemistry_sample_info_id") is None:
128118
logger.warning(
129119
"Skipping Radionuclides nma_SamplePtID=%s - chemistry_sample_info_id not found",
@@ -137,12 +127,6 @@ def _transfer_hook(self, session: Session) -> None:
137127
"Skipped %s Radionuclides records without valid nma_GlobalID",
138128
skipped_global_id,
139129
)
140-
if skipped_thing_id > 0:
141-
logger.warning(
142-
"Skipped %s Radionuclides records without valid Thing",
143-
skipped_thing_id,
144-
)
145-
146130
rows = self._dedupe_rows(row_dicts, key="nma_GlobalID")
147131
insert_stmt = insert(NMA_Radionuclides)
148132
excluded = insert_stmt.excluded
@@ -219,18 +203,15 @@ def int_val(key: str) -> Optional[int]:
219203
)
220204
return None
221205

222-
# Look up Integer FK and thing_id from cache
223-
cache_entry = self._sample_info_cache.get(legacy_sample_pt_id)
224-
chemistry_sample_info_id = cache_entry[0] if cache_entry else None
225-
thing_id = cache_entry[1] if cache_entry else None
206+
# Look up Integer FK from cache
207+
chemistry_sample_info_id = self._sample_info_cache.get(legacy_sample_pt_id)
226208

227209
nma_global_id = self._uuid_val(val("GlobalID"))
228210

229211
return {
230212
# Legacy UUID PK -> nma_global_id (unique audit column)
231213
"nma_GlobalID": nma_global_id,
232214
# FKs
233-
"thing_id": thing_id,
234215
"chemistry_sample_info_id": chemistry_sample_info_id,
235216
# Legacy ID columns (renamed with nma_ prefix)
236217
"nma_SamplePtID": legacy_sample_pt_id,

0 commit comments

Comments
 (0)