Skip to content

Commit 67b4fd6

Browse files
committed
Limit memory use when caching prep info
1 parent 119d4ed commit 67b4fd6

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

qiita_pet/handlers/rest/study_samples.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,28 @@ def detail_maker(**kwargs):
3838
# map of {sample_id: [indices, of, light, prep, info, ...]}
3939
sample_prep_mapping = defaultdict(list)
4040
pt_light = []
41-
for idx, pt in enumerate(study.prep_templates()):
42-
pt_light.append((pt.id, pt.ebi_experiment_accessions,
43-
pt.status, pt.data_type()))
41+
offset = 0
42+
incoming_samples = set(samples)
43+
for pt in study.prep_templates():
44+
prep_samples = set(pt)
45+
overlap = incoming_samples & prep_samples
4446

45-
for ptsample in pt:
46-
sample_prep_mapping[ptsample].append(idx)
47+
if overlap:
48+
# cache if any of or query samples are present on the prep
49+
50+
# reduce accessions to only samples of interest
51+
accessions = pt.ebi_experiment_accessions
52+
overlap_accessions = {i: accessions[i] for i in overlap}
53+
54+
# store the detail we need
55+
pt_light.append((pt.id, overlap_accessions,
56+
pt.status, pt.data_type()))
57+
58+
# only care about mapping the incoming samples
59+
for ptsample in overlap:
60+
sample_prep_mapping[ptsample].append(offset)
61+
62+
offset += 1
4763

4864
details = []
4965
for sample in samples:

0 commit comments

Comments
 (0)