Skip to content

Commit

Permalink
Remove redundant cells queries (interuss#1042)
Browse files Browse the repository at this point in the history
  • Loading branch information
BenjaminPelletier authored Jun 10, 2024
1 parent 1e01739 commit ce9e97d
Showing 1 changed file with 0 additions and 39 deletions.
39 changes: 0 additions & 39 deletions pkg/scd/store/cockroach/operational_intents.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
dsssql "github.com/interuss/dss/pkg/sql"
"github.com/interuss/stacktrace"

"github.com/golang/geo/s2"
"github.com/jackc/pgx/v5"
"github.com/pkg/errors"
)
Expand Down Expand Up @@ -105,10 +104,6 @@ func (s *repo) fetchOperationalIntents(ctx context.Context, q dsssql.Queryable,
}

for _, op := range payload {
if err := s.populateOperationalIntentCells(ctx, q, op); err != nil {
return nil, stacktrace.Propagate(err, "Error populating cells for Operation %s", op.ID)
}

op.UssAvailability = ussAvailabilities[op.Manager]
}

Expand Down Expand Up @@ -142,40 +137,6 @@ func (s *repo) fetchOperationByID(ctx context.Context, q dsssql.Queryable, id ds
return s.fetchOperationalIntent(ctx, q, query, uid)
}

func (s *repo) populateOperationalIntentCells(ctx context.Context, q dsssql.Queryable, o *scdmodels.OperationalIntent) error {
const query = `
SELECT
unnest(cells) as cell_id
FROM
scd_operations
WHERE id = $1`

uid, err := o.ID.PgUUID()
if err != nil {
return stacktrace.Propagate(err, "Failed to convert id to PgUUID")
}
rows, err := q.Query(ctx, query, uid)
if err != nil {
return stacktrace.Propagate(err, "Error in query: %s", query)
}
defer rows.Close()

var cell int64
o.Cells = s2.CellUnion{}

for rows.Next() {
if err := rows.Scan(&cell); err != nil {
return stacktrace.Propagate(err, "Error scanning cell ID row")
}
o.Cells = append(o.Cells, s2.CellID(uint64(cell)))
}
if err := rows.Err(); err != nil {
return stacktrace.Propagate(err, "Error in rows query result")
}

return nil
}

// GetOperation implements repos.Operation.GetOperation.
func (s *repo) GetOperationalIntent(ctx context.Context, id dssmodels.ID) (*scdmodels.OperationalIntent, error) {
return s.fetchOperationByID(ctx, s.q, id)
Expand Down

0 comments on commit ce9e97d

Please sign in to comment.