Skip to content

Commit

Permalink
Add additional check to elide writing empty transaction metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
josephschorr committed Nov 5, 2024
1 parent 0d5b21b commit 4c15452
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion internal/datastore/crdb/crdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ func (cds *crdbDatastore) ReadWriteTx(
}

// If metadata is to be attached, write that row now.
if config.Metadata != nil {
if config.Metadata != nil && len(config.Metadata.GetFields()) > 0 {
expiresAt := time.Now().Add(cds.gcWindow).Add(1 * time.Minute)
insertTransactionMetadata := psql.Insert(tableTransactionMetadata).
Columns(colExpiresAt, colMetadata).
Expand Down
2 changes: 1 addition & 1 deletion internal/datastore/memdb/memdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ func (mdb *memdbDatastore) ReadWriteTx(

tracked := common.NewChanges(revisions.TimestampIDKeyFunc, datastore.WatchRelationships|datastore.WatchSchema, 0)
if tx != nil {
if config.Metadata != nil {
if config.Metadata != nil && len(config.Metadata.GetFields()) > 0 {
if err := tracked.SetRevisionMetadata(ctx, newRevision, config.Metadata.AsMap()); err != nil {
return datastore.NoRevision, err
}
Expand Down
2 changes: 1 addition & 1 deletion internal/datastore/postgres/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ func (pgd *pgDatastore) ReadWriteTx(
err = wrapError(pgx.BeginTxFunc(ctx, pgd.writePool, pgx.TxOptions{IsoLevel: pgx.Serializable}, func(tx pgx.Tx) error {
var err error
var metadata map[string]any
if config.Metadata != nil {
if config.Metadata != nil && len(config.Metadata.GetFields()) > 0 {
metadata = config.Metadata.AsMap()
}

Expand Down
2 changes: 1 addition & 1 deletion internal/datastore/spanner/spanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ func (sd *spannerDatastore) ReadWriteTx(ctx context.Context, fn datastore.TxUser
return &traceableRTX{delegate: spannerRWT}
}

if config.Metadata != nil {
if config.Metadata != nil && len(config.Metadata.GetFields()) > 0 {
// Insert the metadata into the transaction metadata table.
mutation := spanner.Insert(tableTransactionMetadata,
[]string{colTransactionTag, colMetadata},
Expand Down

0 comments on commit 4c15452

Please sign in to comment.