Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions internal/apps/project/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ package project

const (
ProjectObjKey = "project_obj"
// projectItemInsertBatchSize limits batch inserts to avoid exceeding MySQL's placeholder ceiling.
projectItemInsertBatchSize = 1000
)

type DistributionType int8
Expand Down
4 changes: 2 additions & 2 deletions internal/apps/project/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ func (p *Project) CreateItems(ctx context.Context, tx *gorm.DB, items []string,
projectItems[i] = wi.item
}

if err := tx.Create(&projectItems).Error; err != nil {
if err := tx.CreateInBatches(&projectItems, projectItemInsertBatchSize).Error; err != nil {
return err
}

Expand All @@ -259,7 +259,7 @@ func (p *Project) CreateItems(ctx context.Context, tx *gorm.DB, items []string,
projectItems[i] = ProjectItem{ProjectID: p.ID, Content: content}
}

if err := tx.Create(&projectItems).Error; err != nil {
if err := tx.CreateInBatches(&projectItems, projectItemInsertBatchSize).Error; err != nil {
return err
}

Expand Down