develop/batch-jobs #13

Merged
fenpaws merged 11 commits from develop/batch-jobs into main 2024-07-06 21:49:26 +00:00
Showing only changes of commit c20b9143db - Show all commits

View File

@ -3,6 +3,7 @@ package postgres
import ( import (
"context" "context"
"errors" "errors"
"gorm.io/gorm/clause" "gorm.io/gorm/clause"
otterError "git.dragse.it/anthrove/otter-space-sdk/v2/pkg/error" otterError "git.dragse.it/anthrove/otter-space-sdk/v2/pkg/error"
@ -220,7 +221,10 @@ func CreateTagAliasInBatch(ctx context.Context, db *gorm.DB, tagAliases []models
return &otterError.EntityValidationFailed{Reason: "batch size cannot be zero"} return &otterError.EntityValidationFailed{Reason: "batch size cannot be zero"}
} }
result := db.WithContext(ctx).CreateInBatches(tagAliases, batchSize) result := db.WithContext(ctx).Clauses(clause.OnConflict{
Columns: []clause.Column{{Name: "name"}},
DoNothing: true,
}).CreateInBatches(tagAliases, batchSize)
if result.Error != nil { if result.Error != nil {
if errors.Is(result.Error, gorm.ErrDuplicatedKey) { if errors.Is(result.Error, gorm.ErrDuplicatedKey) {
return &otterError.EntityAlreadyExists{} return &otterError.EntityAlreadyExists{}