diff --git a/backfill.go b/backfill.go index 541f34c..6e0f0a1 100644 --- a/backfill.go +++ b/backfill.go @@ -17,7 +17,11 @@ import ( ) func (portal *Portal) forwardBackfillInitial(source *User, thread *Thread) { - defer portal.forwardBackfillLock.Unlock() + log := portal.log + defer func() { + log.Debug().Msg("Forward backfill finished, unlocking lock") + portal.forwardBackfillLock.Unlock() + }() // This should only be called from CreateMatrixRoom which locks forwardBackfillLock before creating the room. if portal.forwardBackfillLock.TryLock() { panic("forwardBackfillInitial() called without locking forwardBackfillLock") @@ -35,14 +39,14 @@ func (portal *Portal) forwardBackfillInitial(source *User, thread *Thread) { return } - with := portal.log.With(). + with := log.With(). Str("action", "initial backfill"). Str("room_id", portal.MXID.String()). Int("limit", limit) if thread != nil { with = with.Str("thread_id", thread.ID) } - log := with.Logger() + log = with.Logger() portal.backfillLimited(log, source, limit, "", thread) } @@ -231,7 +235,6 @@ func (portal *Portal) forwardBatchSend(log zerolog.Logger, source *User, message } } portal.bridge.DB.Message.MassInsert(portal.Key, dbMessages) - log.Info().Msg("Inserted backfilled batch to database") } func (portal *Portal) convertMessageBatch(log zerolog.Logger, source *User, messages []*discordgo.Message, thread *Thread) ([]*event.Event, []*discordgo.Message, []database.Message) { diff --git a/portal.go b/portal.go index f13c69a..6d14f3d 100644 --- a/portal.go +++ b/portal.go @@ -549,13 +549,15 @@ func (portal *Portal) CreateMatrixRoom(user *User, channel *discordgo.Channel) e func (portal *Portal) handleDiscordMessages(msg portalDiscordMessage) { if portal.MXID == "" { - _, ok := msg.msg.(*discordgo.MessageCreate) + msgCreate, ok := msg.msg.(*discordgo.MessageCreate) if !ok { portal.log.Warn().Msg("Can't create Matrix room from non new message event") return } - portal.log.Debug().Msg("Creating Matrix room from incoming message") + portal.log.Debug(). + Str("message_id", msgCreate.ID). + Msg("Creating Matrix room from incoming message") if err := portal.CreateMatrixRoom(msg.user, nil); err != nil { portal.log.Err(err).Msg("Failed to create portal room") return diff --git a/user.go b/user.go index d2a26ee..9890184 100644 --- a/user.go +++ b/user.go @@ -1199,11 +1199,21 @@ func (user *User) pushPortalMessage(msg interface{}, typeName, channelID, guildI return } - portal.discordMessages <- portalDiscordMessage{ + wrappedMsg := portalDiscordMessage{ msg: msg, user: user, thread: thread, } + select { + case portal.discordMessages <- wrappedMsg: + default: + user.log.Warn(). + Str("discord_event", typeName). + Str("guild_id", guildID). + Str("channel_id", channelID). + Msg("Portal message buffer is full") + portal.discordMessages <- wrappedMsg + } } type CustomReadReceipt struct {