Use db.WithTx/WithTx2 instead of TxContext when possible (#35130)
Some checks failed
cron-translations / crowdin-pull (push) Has been skipped
release-nightly / nightly-binary (push) Has been cancelled
release-nightly / nightly-docker-rootful (push) Has been cancelled
release-nightly / nightly-docker-rootless (push) Has been cancelled

This commit is contained in:
Lunny Xiao
2025-07-23 01:02:01 +08:00
committed by GitHub
parent f201dde945
commit 65cd3f5309
56 changed files with 1999 additions and 2640 deletions

View File

@ -755,18 +755,14 @@ func (issue *Issue) HasOriginalAuthor() bool {
// InsertIssues insert issues to database
func InsertIssues(ctx context.Context, issues ...*Issue) error {
ctx, committer, err := db.TxContext(ctx)
if err != nil {
return err
}
defer committer.Close()
for _, issue := range issues {
if err := insertIssue(ctx, issue); err != nil {
return err
return db.WithTx(ctx, func(ctx context.Context) error {
for _, issue := range issues {
if err := insertIssue(ctx, issue); err != nil {
return err
}
}
}
return committer.Commit()
return nil
})
}
func insertIssue(ctx context.Context, issue *Issue) error {