Skip to content

Commit

Permalink
fix(cd-service): removed revision parsing from transaction. (#2149)
Browse files Browse the repository at this point in the history
The cd-service was parsing the git revision inside a transaction. This
meant that if the operation failed we had opened a connection to the
database for no reason.

This PR moves this operation outside of the transaction.

Ref: SRX-0F9ZN3
  • Loading branch information
diogo-nogueira-freiheit authored Nov 29, 2024
1 parent cccfe12 commit d99dd51
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions services/cd-service/pkg/service/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,14 @@ func (o *VersionServiceServer) GetVersion(
state := o.Repository.State()
dbHandler := state.DBHandler
if dbHandler.ShouldUseOtherTables() {
// The gitRevision field is actually not a proper git revision.
// Instead, it has the release number stored with leading zeroes.
releaseVersion, err := reposerver.FromRevision(in.GitRevision)
if err != nil {
return nil, fmt.Errorf("could not parse GitRevision '%s' for app '%s' in env '%s': %w",
in.GitRevision, in.Application, in.Environment, err)
}
res, err := db.WithTransactionT[api.GetVersionResponse](dbHandler, ctx, 1, true, func(ctx context.Context, tx *sql.Tx) (*api.GetVersionResponse, error) {
// The gitRevision field is actually not a proper git revision.
// Instead, it has the release number stored with leading zeroes.
releaseVersion, err := reposerver.FromRevision(in.GitRevision)
if err != nil {
return nil, fmt.Errorf("could not parse GitRevision '%s' for app '%s' in env '%s': %w",
in.GitRevision, in.Application, in.Environment, err)
}
deployment, err := dbHandler.DBSelectSpecificDeployment(ctx, tx, in.Environment, in.Application, releaseVersion)
if err != nil || deployment == nil {
return nil, fmt.Errorf("no deployment found for env='%s' and app='%s': %w", in.Environment, in.Application, err)
Expand Down

0 comments on commit d99dd51

Please sign in to comment.