From a8be4b11a88b3b6e37c64b217a30791b07fa1009 Mon Sep 17 00:00:00 2001 From: Sumner Evans Date: Tue, 5 Apr 2022 12:28:58 -0600 Subject: [PATCH] historysync: start deferred backfill on non-full syncs Co-authored-by: Tulir Asokan --- historysync.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/historysync.go b/historysync.go index c290241..9565fd0 100644 --- a/historysync.go +++ b/historysync.go @@ -239,7 +239,7 @@ func (user *User) handleHistorySync(reCheckQueue chan bool, evt *waProto.History // If this was the initial bootstrap, enqueue immediate backfills for the // most recent portals. If it's the last history sync event, start // backfilling the rest of the history of the portals. - if user.bridge.Config.Bridge.HistorySync.Backfill && (evt.GetSyncType() == waProto.HistorySync_INITIAL_BOOTSTRAP || evt.GetSyncType() == waProto.HistorySync_FULL) { + if user.bridge.Config.Bridge.HistorySync.Backfill && (evt.GetSyncType() == waProto.HistorySync_INITIAL_BOOTSTRAP || evt.GetSyncType() == waProto.HistorySync_FULL || evt.GetSyncType() == waProto.HistorySync_RECENT) { nMostRecent := user.bridge.DB.HistorySyncQuery.GetNMostRecentConversations(user.MXID, user.bridge.Config.Bridge.HistorySync.MaxInitialConversations) for i, conv := range nMostRecent { jid, err := types.ParseJID(conv.ConversationID) @@ -253,9 +253,11 @@ func (user *User) handleHistorySync(reCheckQueue chan bool, evt *waProto.History case waProto.HistorySync_INITIAL_BOOTSTRAP: // Enqueue immediate backfills for the most recent messages first. user.EnqueueImmedateBackfill(portal, i) - case waProto.HistorySync_FULL: - // Enqueue deferred backfills as configured. - user.EnqueueDeferredBackfills(portal, len(nMostRecent), i) + case waProto.HistorySync_FULL, waProto.HistorySync_RECENT: + if evt.GetProgress() >= 99 { + // Enqueue deferred backfills as configured. + user.EnqueueDeferredBackfills(portal, len(nMostRecent), i) + } } }