mirror of
https://github.com/tulir/mautrix-whatsapp
synced 2024-11-11 12:32:13 +01:00
Only enqueue backfill after last history sync blob
This commit is contained in:
parent
2682298c10
commit
357f165581
1 changed files with 11 additions and 12 deletions
|
@ -317,7 +317,7 @@ func (user *User) shouldCreatePortalForHistorySync(conv *database.HistorySyncCon
|
||||||
}
|
}
|
||||||
|
|
||||||
func (user *User) handleHistorySync(backfillQueue *BackfillQueue, evt *waProto.HistorySync) {
|
func (user *User) handleHistorySync(backfillQueue *BackfillQueue, evt *waProto.HistorySync) {
|
||||||
if evt == nil || evt.SyncType == nil || evt.GetSyncType() == waProto.HistorySync_INITIAL_STATUS_V3 || evt.GetSyncType() == waProto.HistorySync_PUSH_NAME {
|
if evt == nil || evt.SyncType == nil || evt.GetSyncType() == waProto.HistorySync_INITIAL_STATUS_V3 || evt.GetSyncType() == waProto.HistorySync_PUSH_NAME || evt.GetSyncType() == waProto.HistorySync_NON_BLOCKING_DATA {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
description := fmt.Sprintf("type %s, %d conversations, chunk order %d, progress: %d", evt.GetSyncType(), len(evt.GetConversations()), evt.GetChunkOrder(), evt.GetProgress())
|
description := fmt.Sprintf("type %s, %d conversations, chunk order %d, progress: %d", evt.GetSyncType(), len(evt.GetConversations()), evt.GetChunkOrder(), evt.GetProgress())
|
||||||
|
@ -380,13 +380,18 @@ func (user *User) handleHistorySync(backfillQueue *BackfillQueue, evt *waProto.H
|
||||||
// most recent portals. If it's the last history sync event, start
|
// most recent portals. If it's the last history sync event, start
|
||||||
// backfilling the rest of the history of the portals.
|
// backfilling the rest of the history of the portals.
|
||||||
if user.bridge.Config.Bridge.HistorySync.Backfill {
|
if user.bridge.Config.Bridge.HistorySync.Backfill {
|
||||||
if evt.GetSyncType() != waProto.HistorySync_INITIAL_BOOTSTRAP && evt.GetProgress() < 98 {
|
expectedLastSyncType := waProto.HistorySync_FULL
|
||||||
|
if !user.bridge.Config.Bridge.HistorySync.RequestFullSync {
|
||||||
|
expectedLastSyncType = waProto.HistorySync_RECENT
|
||||||
|
}
|
||||||
|
if evt.GetProgress() < 99 || evt.GetSyncType() != expectedLastSyncType {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
nMostRecent := user.bridge.DB.HistorySync.GetNMostRecentConversations(user.MXID, user.bridge.Config.Bridge.HistorySync.MaxInitialConversations)
|
nMostRecent := user.bridge.DB.HistorySync.GetNMostRecentConversations(user.MXID, user.bridge.Config.Bridge.HistorySync.MaxInitialConversations)
|
||||||
if len(nMostRecent) > 0 {
|
if len(nMostRecent) > 0 {
|
||||||
// Find the portals for all of the conversations.
|
user.log.Infofln("Got last history sync blob, enqueuing backfills")
|
||||||
|
// Find the portals for all the conversations.
|
||||||
portals := []*Portal{}
|
portals := []*Portal{}
|
||||||
for _, conv := range nMostRecent {
|
for _, conv := range nMostRecent {
|
||||||
jid, err := types.ParseJID(conv.ConversationID)
|
jid, err := types.ParseJID(conv.ConversationID)
|
||||||
|
@ -397,15 +402,9 @@ func (user *User) handleHistorySync(backfillQueue *BackfillQueue, evt *waProto.H
|
||||||
portals = append(portals, user.GetPortalByJID(jid))
|
portals = append(portals, user.GetPortalByJID(jid))
|
||||||
}
|
}
|
||||||
|
|
||||||
switch evt.GetSyncType() {
|
user.EnqueueImmediateBackfills(portals)
|
||||||
case waProto.HistorySync_INITIAL_BOOTSTRAP:
|
user.EnqueueForwardBackfills(portals)
|
||||||
// Enqueue immediate backfills for the most recent messages first.
|
user.EnqueueDeferredBackfills(portals)
|
||||||
user.EnqueueImmediateBackfills(portals)
|
|
||||||
case waProto.HistorySync_FULL, waProto.HistorySync_RECENT:
|
|
||||||
user.EnqueueForwardBackfills(portals)
|
|
||||||
// Enqueue deferred backfills as configured.
|
|
||||||
user.EnqueueDeferredBackfills(portals)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Tell the queue to check for new backfill requests.
|
// Tell the queue to check for new backfill requests.
|
||||||
backfillQueue.ReCheck()
|
backfillQueue.ReCheck()
|
||||||
|
|
Loading…
Reference in a new issue