From c7072e967bd6a32e5468f2a0424f10b704582cbb Mon Sep 17 00:00:00 2001 From: Matt Siwiec Date: Tue, 19 Dec 2023 14:06:20 -0700 Subject: [PATCH] move query for metadata out of transaction (#296) Signed-off-by: Matt Siwiec --- internal/graphapi/pool.resolvers.go | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/internal/graphapi/pool.resolvers.go b/internal/graphapi/pool.resolvers.go index ebadbd842..12c295439 100644 --- a/internal/graphapi/pool.resolvers.go +++ b/internal/graphapi/pool.resolvers.go @@ -172,21 +172,7 @@ func (r *mutationResolver) LoadBalancerPoolDelete(ctx context.Context, id gidx.P return nil, ErrInternalServerError } - defer func() { - if err != nil { - logger.Debugw("rolling back transaction") - if err := tx.Rollback(); err != nil { - logger.Errorw("failed to rollback transaction", "error", err) - } - - return - } - - logger.Debugw("committing transaction") - if err := tx.Commit(); err != nil { - logger.Errorw("failed to commit transaction", "error", err) - } - }() + defer tx.Rollback() // cleanup origins associated with pool origins, err := tx.Origin.Query().Where(predicate.Origin(origin.PoolIDEQ(id))).All(ctx) @@ -208,6 +194,12 @@ func (r *mutationResolver) LoadBalancerPoolDelete(ctx context.Context, id gidx.P return nil, ErrInternalServerError } + logger.Debugw("committing transaction") + if err := tx.Commit(); err != nil { + logger.Errorw("failed to commit transaction", "error", err) + return nil, ErrInternalServerError + } + // find loadbalancers associated with this pool to update loadbalancer metadata status ports, err := r.client.Port.Query().Where(port.HasPoolsWith(pool.IDEQ(id))).All(ctx) if err == nil {