From 8f4d056372f2bf058536109bded9a92ce4a39ff5 Mon Sep 17 00:00:00 2001 From: ahdamin Date: Fri, 13 Dec 2024 14:22:54 +0100 Subject: [PATCH 1/4] Add genotype analysis loading --- genotype_api/database/crud/read.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/genotype_api/database/crud/read.py b/genotype_api/database/crud/read.py index ef2c9de..518e69f 100644 --- a/genotype_api/database/crud/read.py +++ b/genotype_api/database/crud/read.py @@ -247,7 +247,11 @@ def _get_samples_with_analyses_and_genotypes() -> Query: return ( select(Sample) .distinct() - .options(selectinload(Sample.analyses).selectinload(Analysis.genotypes)) + .options( + selectinload(Sample.analyses) + .selectinload(Analysis.genotypes) + .selectinload(Genotype.analysis) + ) .join(Analysis, Analysis.sample_id == Sample.id) ) From aa566bfa885564d59a444a6680226b8a317d31eb Mon Sep 17 00:00:00 2001 From: ahdamin Date: Fri, 13 Dec 2024 14:34:27 +0100 Subject: [PATCH 2/4] Add analyses loading to query --- genotype_api/database/crud/update.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/genotype_api/database/crud/update.py b/genotype_api/database/crud/update.py index 0a12cfa..413f863 100644 --- a/genotype_api/database/crud/update.py +++ b/genotype_api/database/crud/update.py @@ -31,10 +31,14 @@ async def refresh_sample_status( return sample async def update_sample_comment(self, sample_id: str, comment: str) -> Sample: - query: Query = select(Sample).distinct().filter(Sample.id == sample_id) + query: Query = ( + select(Sample).options(selectinload(Sample.analyses)).filter(Sample.id == sample_id) + ) sample: Sample = await self.fetch_one_or_none(query) + if not sample: raise SampleNotFoundError + sample.comment = comment self.session.add(sample) await self.session.commit() From 9b106634dd396fd917189efa0796b4a2597fc5ef Mon Sep 17 00:00:00 2001 From: ahdamin Date: Fri, 13 Dec 2024 15:09:17 +0100 Subject: [PATCH 3/4] Revert to previous --- genotype_api/database/crud/read.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/genotype_api/database/crud/read.py b/genotype_api/database/crud/read.py index 518e69f..ef2c9de 100644 --- a/genotype_api/database/crud/read.py +++ b/genotype_api/database/crud/read.py @@ -247,11 +247,7 @@ def _get_samples_with_analyses_and_genotypes() -> Query: return ( select(Sample) .distinct() - .options( - selectinload(Sample.analyses) - .selectinload(Analysis.genotypes) - .selectinload(Genotype.analysis) - ) + .options(selectinload(Sample.analyses).selectinload(Analysis.genotypes)) .join(Analysis, Analysis.sample_id == Sample.id) ) From 518aa5eb2736338504dd709850d0ad854f30ce8f Mon Sep 17 00:00:00 2001 From: ahdamin Date: Fri, 13 Dec 2024 15:20:30 +0100 Subject: [PATCH 4/4] Add lazy-loading for genotype --- genotype_api/database/crud/update.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/genotype_api/database/crud/update.py b/genotype_api/database/crud/update.py index 413f863..74ac4ba 100644 --- a/genotype_api/database/crud/update.py +++ b/genotype_api/database/crud/update.py @@ -32,7 +32,9 @@ async def refresh_sample_status( async def update_sample_comment(self, sample_id: str, comment: str) -> Sample: query: Query = ( - select(Sample).options(selectinload(Sample.analyses)).filter(Sample.id == sample_id) + select(Sample) + .options(selectinload(Sample.analyses).selectinload(Analysis.genotypes)) + .filter(Sample.id == sample_id) ) sample: Sample = await self.fetch_one_or_none(query)