Skip to content

Commit

Permalink
Merge pull request #1711 from XiMo-210/main
Browse files Browse the repository at this point in the history
sys_export_template.go: 导入Excel时使用批量插入提高性能
  • Loading branch information
pixelmaxQm authored Apr 13, 2024
2 parents 61dd524 + 8c445b2 commit 3c4baa5
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions server/service/system/sys_export_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ func (sysExportTemplateService *SysExportTemplateService) ImportExcel(templateID
return db.Transaction(func(tx *gorm.DB) error {
excelTitle := rows[0]
values := rows[1:]
items := make([]map[string]interface{}, len(values))
for _, row := range values {
var item = make(map[string]interface{})
for ii, value := range row {
Expand All @@ -354,12 +355,10 @@ func (sysExportTemplateService *SysExportTemplateService) ImportExcel(templateID
// item["updated_at"] = time.Now()
//}

cErr := tx.Table(template.TableName).Create(&item).Error
if cErr != nil {
return cErr
}
items = append(items, item)
}
return nil
cErr := tx.Table(template.TableName).CreateInBatches(&items, 1000).Error
return cErr
})
}

Expand Down

0 comments on commit 3c4baa5

Please sign in to comment.