Add global backfill lock

Ensures only a single channel is backfilled at once.
This commit is contained in:
Joonas Myhrberg 2023-08-02 21:57:54 +03:00
parent 5467ab074d
commit e3340d61ec

View file

@ -6,6 +6,7 @@ import (
"encoding/base64"
"fmt"
"sort"
"sync"
"github.com/bwmarrin/discordgo"
"github.com/rs/zerolog"
@ -16,6 +17,8 @@ import (
"go.mau.fi/mautrix-discord/database"
)
var globalBackfillLock sync.Mutex
func (portal *Portal) forwardBackfillInitial(source *User, thread *Thread) {
log := portal.log
defer func() {
@ -27,6 +30,9 @@ func (portal *Portal) forwardBackfillInitial(source *User, thread *Thread) {
panic("forwardBackfillInitial() called without locking forwardBackfillLock")
}
globalBackfillLock.Lock()
defer globalBackfillLock.Unlock()
limit := portal.bridge.Config.Bridge.Backfill.Limits.Initial.Channel
if portal.GuildID == "" {
limit = portal.bridge.Config.Bridge.Backfill.Limits.Initial.DM
@ -78,6 +84,9 @@ func (portal *Portal) ForwardBackfillMissed(source *User, serverLastMessageID st
portal.forwardBackfillLock.Lock()
defer portal.forwardBackfillLock.Unlock()
globalBackfillLock.Lock()
defer globalBackfillLock.Unlock()
var lastMessage *database.Message
if thread != nil {
lastMessage = portal.bridge.DB.Message.GetLastInThread(portal.Key, thread.ID)