1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-11-28 05:03:59 +03:00

Optimise pushprocessor

by not [re]creating RegExps unnecessarily.
This commit is contained in:
lukebarnard
2018-01-05 19:51:17 +00:00
parent f2b7e8b038
commit ca0ed50172

View File

@@ -75,7 +75,7 @@ function PushProcessor(client) {
rawrule.conditions.push({ rawrule.conditions.push({
'kind': 'event_match', 'kind': 'event_match',
'key': 'room_id', 'key': 'room_id',
'pattern': tprule.rule_id, 'value': tprule.rule_id,
}); });
break; break;
case 'sender': case 'sender':
@@ -85,7 +85,7 @@ function PushProcessor(client) {
rawrule.conditions.push({ rawrule.conditions.push({
'kind': 'event_match', 'kind': 'event_match',
'key': 'user_id', 'key': 'user_id',
'pattern': tprule.rule_id, 'value': tprule.rule_id,
}); });
break; break;
case 'content': case 'content':
@@ -95,7 +95,7 @@ function PushProcessor(client) {
rawrule.conditions.push({ rawrule.conditions.push({
'kind': 'event_match', 'kind': 'event_match',
'key': 'content.body', 'key': 'content.body',
'pattern': tprule.pattern, 'regex': new RegExp('(^|\\W)' + globToRegexp(tprule.pattern) + '(\\W|$)'),
}); });
break; break;
} }
@@ -212,14 +212,11 @@ function PushProcessor(client) {
return false; return false;
} }
let pat; if (cond.value) {
if (cond.key == 'content.body') { return cond.value === val;
pat = '(^|\\W)' + globToRegexp(cond.pattern) + '(\\W|$)';
} else {
pat = '^' + globToRegexp(cond.pattern) + '$';
} }
const regex = new RegExp(pat, 'i');
return !!val.match(regex); return !!val.match(cond.regex);
}; };
const globToRegexp = function(glob) { const globToRegexp = function(glob) {