mirror of
https://github.com/ddworken/hishtory.git
synced 2025-06-18 11:06:41 +02:00
Make deletion request auto-retry SQLITE_LOCKED errors since deletion requests will now be much more common with pre-saving support
This commit is contained in:
parent
8bb02ea88c
commit
e3d54e43e8
@ -605,12 +605,14 @@ func HandleDeletionRequests(ctx context.Context, deletionRequests []*shared.Dele
|
||||
db := hctx.GetDb(ctx)
|
||||
for _, request := range deletionRequests {
|
||||
for _, entry := range request.Messages.Ids {
|
||||
err := RetryingDbFunction(func() error {
|
||||
// Note that entry.EndTime is not always present (for pre-saved entries). And likewise,
|
||||
// entry.EntryId is not always present for older entries. So we just check that one of them matches.
|
||||
tx := db.Where("device_id = ? AND (end_time = ? OR entry_id = ?)", entry.DeviceId, entry.EndTime, entry.EntryId)
|
||||
res := tx.Delete(&data.HistoryEntry{})
|
||||
if res.Error != nil {
|
||||
return fmt.Errorf("DB error: %w", res.Error)
|
||||
return tx.Delete(&data.HistoryEntry{}).Error
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("DB error when deleting entries: %w", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user