forked from mirror/mautrix-discord
Add global backfill lock
Ensures only a single channel is backfilled at once.
This commit is contained in:
parent
5467ab074d
commit
e3340d61ec
1 changed files with 9 additions and 0 deletions
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue