Summary
For every delivery observation serialized, evidence_refs_payload(observation.evidence_events) — which builds a reverse("api-event-evidence", ...) URL and a dict per evidence event — is materialized twice: once directly for the evidence_refs key, and once inside delivery_observation_state_payloads.
Location
forensics/views.py:2663-2685
def delivery_observation_payload(observation):
return {
...
"states": delivery_observation_state_payloads(observation), # builds refs (2678)
...
"evidence_refs": evidence_refs_payload(observation.evidence_events), # builds refs again (2672)
}
def delivery_observation_state_payloads(observation):
refs_by_event_id = {
ref["event_id"]: ref for ref in evidence_refs_payload(observation.evidence_events) # 2678
}
...
Impact
On delivery endpoints and the streaming group export, observations with several evidence events pay double the reverse()/dict-construction cost per observation. Prefetch avoids extra SQL, so this is pure redundant CPU (which holds the GIL during export serialization — see docs/deployment.md), not an N+1.
Fix
Compute the ref list once and share it:
def delivery_observation_payload(observation):
evidence_refs = evidence_refs_payload(observation.evidence_events)
return {
...
"states": delivery_observation_state_payloads(observation, evidence_refs),
"evidence_refs": evidence_refs,
}
Relationship to existing issues
The other "computed twice" issues (#165 message traces, #187 sort, #173 engine_source_values, #257 divergent rollup) are all different call sites; this double-build in the observation payload isn't among them.
Filed by an automated code-review pass.
Summary
For every delivery observation serialized,
evidence_refs_payload(observation.evidence_events)— which builds areverse("api-event-evidence", ...)URL and a dict per evidence event — is materialized twice: once directly for theevidence_refskey, and once insidedelivery_observation_state_payloads.Location
forensics/views.py:2663-2685Impact
On delivery endpoints and the streaming group export, observations with several evidence events pay double the
reverse()/dict-construction cost per observation. Prefetch avoids extra SQL, so this is pure redundant CPU (which holds the GIL during export serialization — seedocs/deployment.md), not an N+1.Fix
Compute the ref list once and share it:
Relationship to existing issues
The other "computed twice" issues (#165 message traces, #187 sort, #173
engine_source_values, #257 divergent rollup) are all different call sites; this double-build in the observation payload isn't among them.Filed by an automated code-review pass.