mirror of
https://github.com/ddworken/hishtory.git
synced 2025-06-20 11:57:50 +02:00
Refactor deletion request creation to happen in a transaction to avoid 1-n DB queries
This commit is contained in:
parent
151dfb4009
commit
9f32ae5d2e
@ -243,12 +243,12 @@ func (db *DB) DeletionRequestCreate(ctx context.Context, request *shared.Deletio
|
|||||||
|
|
||||||
fmt.Printf("db.DeletionRequestCreate: Found %d devices\n", len(devices))
|
fmt.Printf("db.DeletionRequestCreate: Found %d devices\n", len(devices))
|
||||||
|
|
||||||
// TODO: maybe this should be a transaction?
|
return db.Transaction(func(tx *gorm.DB) error {
|
||||||
for _, device := range devices {
|
for _, device := range devices {
|
||||||
request.DestinationDeviceId = device.DeviceId
|
request.DestinationDeviceId = device.DeviceId
|
||||||
tx := db.WithContext(ctx).Create(&request)
|
tx := db.WithContext(ctx).Create(&request)
|
||||||
if tx.Error != nil {
|
if tx.Error != nil {
|
||||||
return fmt.Errorf("tx.Error: %w", tx.Error)
|
return fmt.Errorf("create: tx.Error: %w", tx.Error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -257,8 +257,8 @@ func (db *DB) DeletionRequestCreate(ctx context.Context, request *shared.Deletio
|
|||||||
return fmt.Errorf("db.DeleteMessagesFromBackend: %w", err)
|
return fmt.Errorf("db.DeleteMessagesFromBackend: %w", err)
|
||||||
}
|
}
|
||||||
fmt.Printf("addDeletionRequestHandler: Deleted %d rows in the backend\n", numDeleted)
|
fmt.Printf("addDeletionRequestHandler: Deleted %d rows in the backend\n", numDeleted)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *DB) FeedbackCreate(ctx context.Context, feedback *shared.Feedback) error {
|
func (db *DB) FeedbackCreate(ctx context.Context, feedback *shared.Feedback) error {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user