1- import logging
2- import time
3-
41from fastapi import HTTPException
52from fastapi_pagination .ext .sqlalchemy import paginate
63from sqlalchemy import select
2118)
2219from services .query_helper import order_sort_filter
2320
24- logger = logging .getLogger (__name__ )
25-
26-
2721THING_RESPONSE_BASE = (
2822 joinedload (Sample .field_activity )
2923 .joinedload (FieldActivity .field_event )
6054CONTACT_RESPONSE_THING_ASSOCIATIONS = CONTACT_RESPONSE_PARTICIPANT .selectinload (
6155 Contact .thing_associations
6256)
57+ CONTACT_RESPONSE_THING = CONTACT_RESPONSE_THING_ASSOCIATIONS .selectinload (
58+ ThingContactAssociation .thing
59+ )
6360
6461
6562CONTACT_RESPONSE_LOADER_OPTIONS = (
6663 CONTACT_RESPONSE_PARTICIPANT .selectinload (Contact .emails ),
6764 CONTACT_RESPONSE_PARTICIPANT .selectinload (Contact .phones ),
6865 CONTACT_RESPONSE_PARTICIPANT .selectinload (Contact .addresses ),
6966 CONTACT_RESPONSE_PARTICIPANT .selectinload (Contact .incomplete_nma_phones ),
70- CONTACT_RESPONSE_THING_ASSOCIATIONS . selectinload ( ThingContactAssociation . thing ) ,
67+ CONTACT_RESPONSE_THING ,
7168 CONTACT_RESPONSE_PARTICIPANT .selectinload (Contact .notes ),
7269)
7370
@@ -103,8 +100,10 @@ def get_db_samples(
103100 return paginate (query )
104101
105102
106- def get_sample_by_id_with_relationships (session : Session , sample_id : int ) -> Sample :
107- started_at = time .perf_counter ()
103+ def get_sample_by_id_with_relationships (
104+ session : Session ,
105+ sample_id : int ,
106+ ) -> Sample :
108107 sql = select (Sample ).where (Sample .id == sample_id )
109108 sql = sql .options (* SAMPLE_LOADER_OPTIONS )
110109 sample = session .execute (sql ).unique ().scalar_one_or_none ()
@@ -113,16 +112,4 @@ def get_sample_by_id_with_relationships(session: Session, sample_id: int) -> Sam
113112 status_code = HTTP_404_NOT_FOUND ,
114113 detail = f"Sample with ID { sample_id } not found." ,
115114 )
116-
117- duration_ms = round ((time .perf_counter () - started_at ) * 1000 , 2 )
118- logger .info (
119- "sample lookup completed sample_id=%s duration_ms=%s" ,
120- sample_id ,
121- duration_ms ,
122- extra = {
123- "event" : "sample_lookup_completed" ,
124- "sample_id" : sample_id ,
125- "duration_ms" : duration_ms ,
126- },
127- )
128115 return sample
0 commit comments