Add preliminary support for persisting pre-saved history entries remotely

This commit is contained in:
David Dworken
2023-09-21 12:39:04 -07:00
parent a3b865fa6b
commit ff98a7907c
8 changed files with 76 additions and 42 deletions

View File

@@ -600,7 +600,10 @@ func ProcessDeletionRequests(ctx context.Context) error {
db := hctx.GetDb(ctx)
for _, request := range deletionRequests {
for _, entry := range request.Messages.Ids {
res := db.Where("device_id = ? AND end_time = ?", entry.DeviceId, entry.Date).Delete(&data.HistoryEntry{})
// Note that entry.StartTime is not always present (for legacy reasons) and entry.EndTime is also
// not always present (for pre-saved entries). So we just check that one of them matches.
tx := db.Where("device_id = ? AND (start_time = ? OR end_time = ?)", entry.DeviceId, entry.StartTime, entry.EndTime)
res := tx.Delete(&data.HistoryEntry{})
if res.Error != nil {
return fmt.Errorf("DB error: %w", res.Error)
}