Merge pull request #2 from hobbyistlabs-coder/perf-opt-discord-refs-17330908359259718432

 [perf] optimize string concatenation in resolveDiscordRefs
This commit is contained in:
hobbyistlabs-coder 2026-03-13 04:51:41 -04:00 committed by GitHub
commit ac47777f2c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -578,6 +578,11 @@ func (c *DiscordChannel) resolveDiscordRefs(s *discordgo.Session, text string, g
// 2. Expand Discord message links (max 3, same guild only)
matches := msgLinkRe.FindAllStringSubmatch(text, 3)
if len(matches) == 0 {
return text
}
var sb strings.Builder
sb.WriteString(text)
for _, m := range matches {
if len(m) < 4 {
continue
@ -595,10 +600,10 @@ func (c *DiscordChannel) resolveDiscordRefs(s *discordgo.Session, text string, g
if msg.Author != nil {
author = msg.Author.Username
}
text += fmt.Sprintf("\n[linked message from %s]: %s", author, msg.Content)
fmt.Fprintf(&sb, "\n[linked message from %s]: %s", author, msg.Content)
}
return text
return sb.String()
}
// stripBotMention removes the bot mention from the message content.