Skip to content

Commit

Permalink
Clean up comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ahdamin committed Oct 9, 2024
1 parent 09f3d36 commit dcb8078
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 18 deletions.
15 changes: 1 addition & 14 deletions genotype_api/database/crud/read.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -97,17 +96,14 @@ 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)
return result.scalars().first()

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(
Expand Down Expand Up @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion genotype_api/database/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
1 change: 0 additions & 1 deletion genotype_api/security.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 0 additions & 2 deletions genotype_api/services/endpoint_services/sample_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit dcb8078

Please sign in to comment.