mirror of
https://github.com/superseriousbusiness/gotosocial
synced 2025-06-05 21:59:39 +02:00
[performance] cache v2 filter keyword regular expressions (#2903)
* add caching of filterkeyword regular expressions * formatting * fix WholeWord nil check
This commit is contained in:
@@ -22,7 +22,6 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"math"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -746,18 +745,9 @@ func (c *Converter) statusToAPIFilterResults(
|
||||
keywordMatches := make([]string, 0, len(filter.Keywords))
|
||||
fields := filterableTextFields(s)
|
||||
for _, filterKeyword := range filter.Keywords {
|
||||
wholeWord := util.PtrValueOr(filterKeyword.WholeWord, false)
|
||||
wordBreak := ``
|
||||
if wholeWord {
|
||||
wordBreak = `\b`
|
||||
}
|
||||
re, err := regexp.Compile(`(?i)` + wordBreak + regexp.QuoteMeta(filterKeyword.Keyword) + wordBreak)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var isMatch bool
|
||||
for _, field := range fields {
|
||||
if re.MatchString(field) {
|
||||
if filterKeyword.Regexp.MatchString(field) {
|
||||
isMatch = true
|
||||
break
|
||||
}
|
||||
|
Reference in New Issue
Block a user