Skip to content

Commit

Permalink
Merge pull request #5008 from SpiritCroc/globstar
Browse files Browse the repository at this point in the history
Speed up event match regex evaluation for big messages
  • Loading branch information
bmarty authored Jan 25, 2022
2 parents f914717 + af34399 commit 63b3def
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog.d/5008.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Big messages taking inappropriately long to evaluate .m.rule.roomnotif push rules
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,12 @@ class EventMatchCondition(
if (wordsOnly) {
value.caseInsensitiveFind(pattern)
} 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)
regex.containsMatchIn(value)
}
Expand Down

0 comments on commit 63b3def

Please sign in to comment.