mirror of
https://github.com/ddworken/hishtory.git
synced 2024-11-23 00:34:27 +01:00
Make presaving query slightly more specific, and delete res.RowsAffected check since it can cause flaky errors if a command is run twice very quickly
This commit is contained in:
parent
3253883198
commit
c21d443fa6
@ -230,7 +230,7 @@ func deletePresavedEntries(ctx context.Context, entry *data.HistoryEntry) error
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to query for pre-saved history entry: %w", err)
|
||||
}
|
||||
matchingEntryQuery = matchingEntryQuery.Where("command = ?", entry.Command).Session(&gorm.Session{})
|
||||
matchingEntryQuery = matchingEntryQuery.Where("command = ?", entry.Command).Where("device_id = ?", entry.DeviceId).Session(&gorm.Session{})
|
||||
|
||||
// Get the presaved entry since we need it for doing remote deletes
|
||||
presavedEntry, err := lib.RetryingDbFunctionWithResult(func() (data.HistoryEntry, error) {
|
||||
@ -251,9 +251,6 @@ func deletePresavedEntries(ctx context.Context, entry *data.HistoryEntry) error
|
||||
if res.Error != nil {
|
||||
return fmt.Errorf("failed to delete pre-saved history entry (expected command=%#v): %w", entry.Command, res.Error)
|
||||
}
|
||||
if res.RowsAffected > 1 {
|
||||
return fmt.Errorf("attempted to delete pre-saved entry, but something went wrong since we deleted %d rows", res.RowsAffected)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
err = lib.RetryingDbFunction(deletePresavedEntryFunc)
|
||||
|
Loading…
Reference in New Issue
Block a user