backfill: fixed bug where the media backfill loop would sleep too often

If the number of requested message was a multiple of the number of batch
events, then it would sleep on every single other message (even if not
an errored media message).
This commit is contained in:
Sumner Evans 2022-04-28 15:40:15 -06:00
parent d898aefff1
commit 76c6d0bf87
No known key found for this signature in database
GPG key ID: 8904527AB50022FD

View file

@ -102,10 +102,11 @@ func (user *User) handleBackfillRequestsLoop(backfillRequests chan *database.Bac
// requesting any media that errored.
requested := 0
for _, msg := range user.bridge.DB.Message.GetMessagesBetween(portal.Key, startTime, endTime) {
if requested > 0 && requested%req.MaxBatchEvents == 0 {
time.Sleep(time.Duration(req.BatchDelay) * time.Second)
}
if msg.Error == database.MsgErrMediaNotFound {
if requested > 0 && requested%req.MaxBatchEvents == 0 {
time.Sleep(time.Duration(req.BatchDelay) * time.Second)
}
portal.requestMediaRetry(user, msg.MXID)
requested += 1
}