Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions schemas/well_details.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,4 @@ class WellDetailsResponse(BaseModel):
deployments: list[DeploymentResponse] = Field(default_factory=list)
well_screens: list[WellScreenBaseResponse] = Field(default_factory=list)
field_events: list[WellDetailsFieldEventResponse] = Field(default_factory=list)
first_field_event: WellDetailsFieldEventResponse | None = None
38 changes: 25 additions & 13 deletions services/well_details_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,34 +111,46 @@ def get_well_details_payload(
.order_by(WellScreen.screen_depth_top.asc(), WellScreen.id.asc())
).all()

_participant_options = selectinload(
FieldEvent.field_event_participants
).selectinload(FieldEventParticipant.participant)
_activity_options = [
selectinload(FieldEvent.field_activities)
.selectinload(FieldActivity.samples)
.selectinload(Sample.field_event_participant)
.selectinload(FieldEventParticipant.participant),
selectinload(FieldEvent.field_activities)
.selectinload(FieldActivity.samples)
.selectinload(Sample.observations)
.selectinload(Observation.parameter),
]

with _payload_stage_timer("well_details", "load_field_events", thing_id):
field_events = session.scalars(
select(FieldEvent)
.where(FieldEvent.thing_id == well.id)
.options(
selectinload(FieldEvent.field_event_participants).selectinload(
FieldEventParticipant.participant
),
selectinload(FieldEvent.field_activities)
.selectinload(FieldActivity.samples)
.selectinload(Sample.field_event_participant)
.selectinload(FieldEventParticipant.participant),
selectinload(FieldEvent.field_activities)
.selectinload(FieldActivity.samples)
.selectinload(Sample.observations)
.selectinload(Observation.parameter),
)
.options(_participant_options, *_activity_options)
.order_by(FieldEvent.event_date.desc(), FieldEvent.id.desc())
.limit(field_event_limit)
).all()

with _payload_stage_timer("well_details", "load_first_field_event", thing_id):
first_field_event = session.scalars(
select(FieldEvent)
.where(FieldEvent.thing_id == well.id)
.options(_participant_options)
.order_by(FieldEvent.event_date.asc(), FieldEvent.id.asc())
.limit(1)
).first()

return {
"well": well,
"contacts": contacts,
"sensors": sensors,
"deployments": deployments,
"well_screens": well_screens,
"field_events": field_events,
"first_field_event": first_field_event,
}


Expand Down
Loading