From b7be599769014329f51f04878f138e26dd396ebf Mon Sep 17 00:00:00 2001 From: James Houlahan Date: Thu, 24 Nov 2022 13:04:00 +0100 Subject: [PATCH] GODT-2151: Sync backwards to please product people --- internal/user/sync.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/internal/user/sync.go b/internal/user/sync.go index 1b288bec..c81b480d 100644 --- a/internal/user/sync.go +++ b/internal/user/sync.go @@ -195,11 +195,19 @@ func syncMessages( defer cancel() // Determine which messages to sync. - messageIDs, err := client.GetMessageIDs(ctx, vault.SyncStatus().LastMessageID) + messageIDs, err := client.GetMessageIDs(ctx, "") if err != nil { return fmt.Errorf("failed to get message IDs to sync: %w", err) } + // Reverse the order of the message IDs so that the newest messages are synced first. + xslices.Reverse(messageIDs) + + // If we have a message ID that we've already synced, then we can skip all messages before it. + if idx := xslices.Index(messageIDs, vault.SyncStatus().LastMessageID); idx >= 0 { + messageIDs = messageIDs[idx+1:] + } + // Track the amount of time to process all the messages. syncStartTime := time.Now() defer func() { logrus.WithField("duration", time.Since(syncStartTime)).Info("Message sync completed") }() @@ -297,7 +305,7 @@ func syncMessages( } flushUpdateCh <- flushUpdate{ - messageID: batch[len(batch)-1].messageID, + messageID: batch[0].messageID, noOps: noopUpdates, batchLen: len(batch), }