From 9bfd4bf173e3b0cdd72b6bff58f2b8bf17eb7f3f Mon Sep 17 00:00:00 2001 From: David Dworken Date: Sun, 9 Oct 2022 17:13:40 -0700 Subject: [PATCH] Make uploading skipped history entries more efficient and use only one HTTP request --- hishtory.go | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/hishtory.go b/hishtory.go index 70138b1..e6bd102 100644 --- a/hishtory.go +++ b/hishtory.go @@ -263,16 +263,14 @@ func maybeUploadSkippedHistoryEntries(ctx *context.Context) error { return fmt.Errorf("failed to retrieve history entries that haven't been uploaded yet: %v", err) } hctx.GetLogger().Printf("Uploading %d history entries that previously failed to upload (query=%#v)\n", len(entries), query) - for _, entry := range entries { - jsonValue, err := lib.EncryptAndMarshal(config, []*data.HistoryEntry{entry}) - if err != nil { - return err - } - _, err = lib.ApiPost("/api/v1/submit?source_device_id="+config.DeviceId, "application/json", jsonValue) - if err != nil { - // Failed to upload the history entry, so we must still be offline. So just return nil and we'll try again later. - return nil - } + jsonValue, err := lib.EncryptAndMarshal(config, entries) + if err != nil { + return err + } + _, err = lib.ApiPost("/api/v1/submit?source_device_id="+config.DeviceId, "application/json", jsonValue) + if err != nil { + // Failed to upload the history entry, so we must still be offline. So just return nil and we'll try again later. + return nil } // Mark down that we persisted it