From ac522ed600f52ee33564a6fcc94f5da6e81e33cc Mon Sep 17 00:00:00 2001 From: Matt Baer Date: Tue, 17 Mar 2020 13:43:25 -0400 Subject: [PATCH] Reuse mention regex This makes the app less error-prone by avoiding a regexp.MustCompile() call in the ActivityObject() method, saves CPU work, and reuses code. --- posts.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/posts.go b/posts.go index c632ba9..15176b7 100644 --- a/posts.go +++ b/posts.go @@ -1175,8 +1175,7 @@ func (p *PublicPost) ActivityObject(app *App) *activitystreams.Object { stripper := bluemonday.StrictPolicy() content := stripper.Sanitize(p.Content) - mentionRegex := regexp.MustCompile(`@[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]+\b`) - mentions := mentionRegex.FindAllString(content, -1) + mentions := mentionReg.FindAllString(content, -1) for _, handle := range mentions { actorIRI, err := app.db.GetProfilePageFromHandle(app, handle)