Roll-forward "Add preliminary support for persisting pre-saved history entries remotely"

This rolls-forward commit 66916c27cb.
This commit is contained in:
David Dworken
2023-09-22 13:13:46 -07:00
parent dc166ec089
commit 2a5a6d65c4
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)
}