Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use update instead of CreateInBatches in CompleteMultipartUpload #776

Merged
merged 11 commits into from
Nov 30, 2023
19 changes: 10 additions & 9 deletions stores/multipart.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,15 +403,16 @@ func (s *SQLStore) CompleteMultipartUpload(ctx context.Context, bucket, path str
// clear the ID to make sure new slices are created with IDs in
// ascending order.
for i := range slices {
slices[i].ID = 0
slices[i].DBObjectID = &obj.ID
slices[i].ObjectIndex = uint(i + 1)
slices[i].DBMultipartPartID = nil
}

// Save updated slices.
if err := tx.CreateInBatches(slices, 100).Error; err != nil {
return fmt.Errorf("failed to save slices: %w", err)
err = tx.Model(&dbSlice{}).
ChrisSchinnerl marked this conversation as resolved.
Show resolved Hide resolved
Where("id", slices[i].ID).
Updates(map[string]interface{}{
"db_object_id": obj.ID,
"object_index": uint(i + 1),
"db_multipart_part_id": nil,
}).Error
if err != nil {
return fmt.Errorf("failed to update slice %v: %w", i, err)
}
}

// Delete the multipart upload.
Expand Down