mirror of
https://github.com/tulir/mautrix-whatsapp
synced 2024-12-04 20:52:54 +01:00
backfill: handle ratelimits when fetching group info
This commit is contained in:
parent
b821d83eee
commit
8bc8b8afd6
3 changed files with 18 additions and 4 deletions
2
go.mod
2
go.mod
|
@ -11,7 +11,7 @@ require (
|
|||
github.com/rs/zerolog v1.33.0
|
||||
go.mau.fi/util v0.8.1
|
||||
go.mau.fi/webp v0.1.0
|
||||
go.mau.fi/whatsmeow v0.0.0-20241015144315-3fa42c3d6a28
|
||||
go.mau.fi/whatsmeow v0.0.0-20241030134844-97cdda6998ea
|
||||
golang.org/x/exp v0.0.0-20241009180824-f66d83c29e7c
|
||||
golang.org/x/image v0.21.0
|
||||
golang.org/x/net v0.30.0
|
||||
|
|
4
go.sum
4
go.sum
|
@ -69,8 +69,8 @@ go.mau.fi/util v0.8.1 h1:Ga43cz6esQBYqcjZ/onRoVnYWoUwjWbsxVeJg2jOTSo=
|
|||
go.mau.fi/util v0.8.1/go.mod h1:T1u/rD2rzidVrBLyaUdPpZiJdP/rsyi+aTzn0D+Q6wc=
|
||||
go.mau.fi/webp v0.1.0 h1:BHObH/DcFntT9KYun5pDr0Ot4eUZO8k2C7eP7vF4ueA=
|
||||
go.mau.fi/webp v0.1.0/go.mod h1:e42Z+VMFrUMS9cpEwGRIor+lQWO8oUAyPyMtcL+NMt8=
|
||||
go.mau.fi/whatsmeow v0.0.0-20241015144315-3fa42c3d6a28 h1:Kb0UAafF46p2gJfrxP27jxLUtn1oEWD41g+IddxjQ3U=
|
||||
go.mau.fi/whatsmeow v0.0.0-20241015144315-3fa42c3d6a28/go.mod h1:UvaXcdb8y5Mryj2LSXAMw7u4/exnWJIXn8Gvpmf6ndI=
|
||||
go.mau.fi/whatsmeow v0.0.0-20241030134844-97cdda6998ea h1:wI4bFBotPCPAjh+6+0p9R5VDCQX6Dg/SqUunaONbVDY=
|
||||
go.mau.fi/whatsmeow v0.0.0-20241030134844-97cdda6998ea/go.mod h1:UvaXcdb8y5Mryj2LSXAMw7u4/exnWJIXn8Gvpmf6ndI=
|
||||
go.mau.fi/zeroconfig v0.1.3 h1:As9wYDKmktjmNZW5i1vn8zvJlmGKHeVxHVIBMXsm4kM=
|
||||
go.mau.fi/zeroconfig v0.1.3/go.mod h1:NcSJkf180JT+1IId76PcMuLTNa1CzsFFZ0nBygIQM70=
|
||||
golang.org/x/crypto v0.28.0 h1:GBDwsMXVQi34v5CCYUm2jkJvu4cbtru2U4TN2PSyQnw=
|
||||
|
|
|
@ -194,10 +194,15 @@ func (wa *WhatsAppClient) createPortalsFromHistorySync(ctx context.Context) {
|
|||
log.Err(err).Msg("Failed to get recent conversations from database")
|
||||
return
|
||||
}
|
||||
for _, conv := range conversations {
|
||||
log.Info().Int("conversation_count", len(conversations)).Msg("Creating portals from history sync")
|
||||
rateLimitErrors := 0
|
||||
for i := 0; i < len(conversations); i++ {
|
||||
conv := conversations[i]
|
||||
if conv.ChatJID == types.StatusBroadcastJID && !wa.Main.Config.EnableStatusBroadcast {
|
||||
continue
|
||||
}
|
||||
// TODO can the chat info fetch be avoided entirely?
|
||||
time.Sleep(time.Duration(rateLimitErrors) * time.Second)
|
||||
wrappedInfo, err := wa.getChatInfo(ctx, conv.ChatJID, conv)
|
||||
if errors.Is(err, whatsmeow.ErrNotInGroup) {
|
||||
log.Debug().Stringer("chat_jid", conv.ChatJID).
|
||||
|
@ -207,6 +212,14 @@ func (wa *WhatsAppClient) createPortalsFromHistorySync(ctx context.Context) {
|
|||
log.Err(err).Msg("Failed to delete historical messages for portal")
|
||||
}
|
||||
continue
|
||||
} else if errors.Is(err, whatsmeow.ErrIQRateOverLimit) {
|
||||
rateLimitErrors++
|
||||
i--
|
||||
log.Err(err).Stringer("chat_jid", conv.ChatJID).
|
||||
Int("error_count", rateLimitErrors).
|
||||
Msg("Ratelimit error getting chat info, retrying after sleep")
|
||||
time.Sleep(time.Duration(rateLimitErrors) * time.Minute)
|
||||
continue
|
||||
} else if err != nil {
|
||||
log.Err(err).Stringer("chat_jid", conv.ChatJID).Msg("Failed to get chat info")
|
||||
continue
|
||||
|
@ -222,6 +235,7 @@ func (wa *WhatsAppClient) createPortalsFromHistorySync(ctx context.Context) {
|
|||
LatestMessageTS: conv.LastMessageTimestamp,
|
||||
})
|
||||
}
|
||||
log.Info().Int("conversation_count", len(conversations)).Msg("Finished creating portals from history sync")
|
||||
}
|
||||
|
||||
func (wa *WhatsAppClient) FetchMessages(ctx context.Context, params bridgev2.FetchMessagesParams) (*bridgev2.FetchMessagesResponse, error) {
|
||||
|
|
Loading…
Reference in a new issue