From dcb807879de752e5b1251a78115239fe90dbe986 Mon Sep 17 00:00:00 2001 From: ahdamin Date: Wed, 9 Oct 2024 11:13:22 +0200 Subject: [PATCH] Clean up comments --- genotype_api/database/crud/read.py | 15 +-------------- genotype_api/database/store.py | 2 +- genotype_api/security.py | 1 - .../services/endpoint_services/sample_service.py | 2 -- 4 files changed, 2 insertions(+), 18 deletions(-) diff --git a/genotype_api/database/crud/read.py b/genotype_api/database/crud/read.py index 60fd18a..d7b2ec3 100644 --- a/genotype_api/database/crud/read.py +++ b/genotype_api/database/crud/read.py @@ -81,7 +81,6 @@ async def get_analyses_by_type_between_dates( filtered_query = filtered_query.options(selectinload(Analysis.genotypes)) - # Execute the query asynchronously result = await self.session.execute(filtered_query) return result.scalars().all() @@ -97,7 +96,6 @@ async def get_analysis_by_type_and_sample_id( type=analysis_type, ) - # Add selectinload to eagerly load genotypes filtered_query = filtered_query.options(selectinload(Analysis.genotypes)) result = await self.session.execute(filtered_query) @@ -105,9 +103,7 @@ async def get_analysis_by_type_and_sample_id( async def get_plate_by_id(self, plate_id: int) -> Plate: plates: Query = self._get_query(Plate).options( - selectinload(Plate.analyses).selectinload( - Analysis.sample - ) # Eager loading of analyses and samples + selectinload(Plate.analyses).selectinload(Analysis.sample) ) filter_functions = [PlateFilter.BY_ID] filtered_query = apply_plate_filter( @@ -206,23 +202,14 @@ def _get_samples(query: Query, sample_id: str) -> Query: return query.filter(Sample.id.contains(sample_id)) async def get_sample_by_id(self, sample_id: str) -> Sample: - # Start by getting a base query for Sample samples: Query = self._get_query(Sample) - - # Define the filter functions for filtering by Sample ID filter_functions = [SampleFilter.BY_ID] - - # Apply the filters using apply_sample_filter filtered_query = apply_sample_filter( samples=samples, filter_functions=filter_functions, sample_id=sample_id ) - - # Ensure we load related analyses and genotypes using selectinload to avoid lazy loading filtered_query = filtered_query.options( selectinload(Sample.analyses).selectinload(Analysis.genotypes) ) - - # Execute the query asynchronously result = await self.session.execute(filtered_query) return result.scalars().first() diff --git a/genotype_api/database/store.py b/genotype_api/database/store.py index 56012b6..b4ba9b7 100644 --- a/genotype_api/database/store.py +++ b/genotype_api/database/store.py @@ -45,6 +45,6 @@ async def get_store() -> AsyncGenerator[Store, None]: """Return a Store instance.""" store = await Store.create() try: - yield store # Yield the store for the duration of the request + yield store finally: await store.session.close() diff --git a/genotype_api/security.py b/genotype_api/security.py index 31f1199..259df6d 100644 --- a/genotype_api/security.py +++ b/genotype_api/security.py @@ -75,7 +75,6 @@ async def get_active_user( detail="Invalid or expired token", ) - # Now check for the presence of "payload" and "email" safely payload = token_info.get("payload") if not payload or "email" not in payload: raise HTTPException( diff --git a/genotype_api/services/endpoint_services/sample_service.py b/genotype_api/services/endpoint_services/sample_service.py index 0f97cad..0d159ad 100644 --- a/genotype_api/services/endpoint_services/sample_service.py +++ b/genotype_api/services/endpoint_services/sample_service.py @@ -65,13 +65,11 @@ def _get_sample_response(self, sample: Sample) -> SampleResponse: ) async def get_sample(self, sample_id: str) -> SampleResponse: - # Use the ReadHandler to fetch the sample sample: Sample = await self.store.get_sample_by_id(sample_id) if not sample: raise SampleNotFoundError - # If sample has two analyses and no status, refresh its status if len(sample.analyses) == 2 and not sample.status: sample: Sample = await self.store.refresh_sample_status(sample=sample)