From 6d601f10bf4e8130ac9cda1d780edeaa0451cfe1 Mon Sep 17 00:00:00 2001 From: wing-utm-sharing-airspace Date: Tue, 14 Jul 2026 12:57:36 -0700 Subject: [PATCH] Only search for operational intents if needed Just a minor copy/paste to avoid one database call if a client did not request `notify_for_operational_intents` during Subscription creation. --- pkg/scd/subscriptions_handler.go | 39 ++++++++++++++++---------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/pkg/scd/subscriptions_handler.go b/pkg/scd/subscriptions_handler.go index 3aec27e5b..62129aab0 100644 --- a/pkg/scd/subscriptions_handler.go +++ b/pkg/scd/subscriptions_handler.go @@ -211,26 +211,6 @@ func (a *Server) PutSubscription(ctx context.Context, manager string, subscripti return stacktrace.NewError("UpsertSubscription returned no Subscription for ID: %s", id) } - // Find relevant Operations - var relevantOperations []*scdmodels.OperationalIntent - if len(sub.Cells) > 0 { - ops, err := r.SearchOperationalIntents(ctx, &dssmodels.Volume4D{ - StartTime: sub.StartTime, - EndTime: sub.EndTime, - SpatialVolume: &dssmodels.Volume3D{ - AltitudeLo: sub.AltitudeLo, - AltitudeHi: sub.AltitudeHi, - Footprint: dssmodels.GeometryFunc(func() (s2.CellUnion, error) { - return sub.Cells, nil - }), - }, - }) - if err != nil { - return stacktrace.Propagate(err, "Could not search Operations in repo") - } - relevantOperations = ops - } - // Convert Subscription to REST p, err := sub.ToRest(dependentOpIds) if err != nil { @@ -241,6 +221,25 @@ func (a *Server) PutSubscription(ctx context.Context, manager string, subscripti } if sub.NotifyForOperationalIntents { + // Find relevant Operations + var relevantOperations []*scdmodels.OperationalIntent + if len(sub.Cells) > 0 { + ops, err := r.SearchOperationalIntents(ctx, &dssmodels.Volume4D{ + StartTime: sub.StartTime, + EndTime: sub.EndTime, + SpatialVolume: &dssmodels.Volume3D{ + AltitudeLo: sub.AltitudeLo, + AltitudeHi: sub.AltitudeHi, + Footprint: dssmodels.GeometryFunc(func() (s2.CellUnion, error) { + return sub.Cells, nil + }), + }, + }) + if err != nil { + return stacktrace.Propagate(err, "Could not search Operations in repo") + } + relevantOperations = ops + } // Attach Operations to response opIntentRefs := make([]restapi.OperationalIntentReference, 0, len(relevantOperations)) for _, op := range relevantOperations {