diff --git a/changelog.d/5008.bugfix b/changelog.d/5008.bugfix new file mode 100644 index 0000000000..3c2f009160 --- /dev/null +++ b/changelog.d/5008.bugfix @@ -0,0 +1 @@ +Big messages taking inappropriately long to evaluate .m.rule.roomnotif push rules diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/pushrules/EventMatchCondition.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/pushrules/EventMatchCondition.kt index eec5b0a402..d82365cace 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/pushrules/EventMatchCondition.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/pushrules/EventMatchCondition.kt @@ -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) }