Merge pull request #5008 from SpiritCroc/globstar

Speed up event match regex evaluation for big messages
This commit is contained in:
Benoit Marty 2022-01-25 15:52:55 +01:00 committed by GitHub
commit 63b3def667
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 1 deletions

1
changelog.d/5008.bugfix Normal file
View File

@ -0,0 +1 @@
Big messages taking inappropriately long to evaluate .m.rule.roomnotif push rules

View File

@ -56,7 +56,12 @@ class EventMatchCondition(
if (wordsOnly) { if (wordsOnly) {
value.caseInsensitiveFind(pattern) value.caseInsensitiveFind(pattern)
} else { } else {
val modPattern = if (pattern.hasSpecialGlobChar()) pattern.simpleGlobToRegExp() else "*$pattern*".simpleGlobToRegExp() val modPattern = if (pattern.hasSpecialGlobChar())
// Regex.containsMatchIn() is way faster without leading and trailing
// stars, that don't make any difference for the evaluation result
pattern.removePrefix("*").removeSuffix("*").simpleGlobToRegExp()
else
pattern.simpleGlobToRegExp()
val regex = Regex(modPattern, RegexOption.DOT_MATCHES_ALL) val regex = Regex(modPattern, RegexOption.DOT_MATCHES_ALL)
regex.containsMatchIn(value) regex.containsMatchIn(value)
} }