Skip to content

Commit b3b14ce

Browse files
fixed lint
1 parent 8bda154 commit b3b14ce

File tree

2 files changed

+20
-21
lines changed

2 files changed

+20
-21
lines changed

dialect/sql/sqlgraph/graph.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -791,10 +791,7 @@ func CreateNode(ctx context.Context, drv dialect.Driver, spec *CreateSpec) error
791791
cr := &creator{CreateSpec: spec, graph: gr}
792792
return cr.node(ctx, d)
793793
}
794-
if retry := getRetryExecutor(drv); retry != nil {
795-
return retry.DoTx(ctx, op, spec.RetryConfig.Options...)
796-
}
797-
return op(ctx, drv)
794+
return execWithRetryTx(ctx, drv, op, spec.RetryConfig.Options)
798795
}
799796

800797
// BatchCreate applies the BatchCreateSpec on the graph.
@@ -804,8 +801,13 @@ func BatchCreate(ctx context.Context, drv dialect.Driver, spec *BatchCreateSpec)
804801
cr := &batchCreator{BatchCreateSpec: spec, graph: gr}
805802
return cr.nodes(ctx, d)
806803
}
804+
return execWithRetryTx(ctx, drv, op, spec.RetryConfig.Options)
805+
}
806+
807+
// execWithRetryTx executes the operation with retry if available, otherwise executes directly.
808+
func execWithRetryTx(ctx context.Context, drv dialect.Driver, op func(context.Context, dialect.Driver) error, opts []any) error {
807809
if retry := getRetryExecutor(drv); retry != nil {
808-
return retry.DoTx(ctx, op, spec.RetryConfig.Options...)
810+
return retry.DoTx(ctx, op, opts...)
809811
}
810812
return op(ctx, drv)
811813
}

dialect/ydb/retry.go

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,13 @@ func (r *RetryExecutor) Do(
3131
fn func(ctx context.Context, drv dialect.Driver) error,
3232
opts ...any,
3333
) error {
34-
retryOpts := make([]retry.Option, 0, len(opts))
35-
for _, opt := range opts {
36-
if ro, ok := opt.(retry.Option); ok {
37-
retryOpts = append(retryOpts, ro)
38-
}
39-
}
40-
4134
return retry.Do(
4235
ctx,
4336
r.db,
4437
func(ctx context.Context, conn *sql.Conn) error {
4538
return fn(ctx, NewRetryDriver(conn))
4639
},
47-
retry.WithDoRetryOptions(retryOpts...),
40+
retry.WithDoRetryOptions(toRetryOptions(opts)...),
4841
)
4942
}
5043

@@ -56,23 +49,27 @@ func (r *RetryExecutor) DoTx(
5649
fn func(ctx context.Context, drv dialect.Driver) error,
5750
opts ...any,
5851
) error {
59-
retryOpts := make([]retry.Option, 0, len(opts))
60-
for _, opt := range opts {
61-
if ro, ok := opt.(retry.Option); ok {
62-
retryOpts = append(retryOpts, ro)
63-
}
64-
}
65-
6652
return retry.DoTx(
6753
ctx,
6854
r.db,
6955
func(ctx context.Context, tx *sql.Tx) error {
7056
return fn(ctx, NewTxRetryDriver(tx))
7157
},
72-
retry.WithDoTxRetryOptions(retryOpts...),
58+
retry.WithDoTxRetryOptions(toRetryOptions(opts)...),
7359
)
7460
}
7561

62+
// toRetryOptions converts a slice of any options to retry.Option slice
63+
func toRetryOptions(opts []any) []retry.Option {
64+
retryOpts := make([]retry.Option, 0, len(opts))
65+
for _, opt := range opts {
66+
if ro, ok := opt.(retry.Option); ok {
67+
retryOpts = append(retryOpts, ro)
68+
}
69+
}
70+
return retryOpts
71+
}
72+
7673
// RetryDriver is designed for use only in sqlgraph,
7774
// specifically - in retry.DoTx callbacks
7875
type RetryDriver struct {

0 commit comments

Comments
 (0)