Support for MSC3758: exact_event_match push condition (#14964)

This specifies to search for an exact value match, instead of
string globbing. It only works across non-compound JSON values
(null, boolean, integer, and strings).
This commit is contained in:
Patrick Cloke 2023-02-10 12:37:07 -05:00 committed by GitHub
parent cf5233b783
commit 14be78d492
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 356 additions and 41 deletions

View file

@ -16,6 +16,7 @@
use std::collections::BTreeSet;
use synapse::push::{
evaluator::PushRuleEvaluator, Condition, EventMatchCondition, FilteredPushRules, PushRules,
SimpleJsonValue,
};
use test::Bencher;
@ -24,9 +25,18 @@ extern crate test;
#[bench]
fn bench_match_exact(b: &mut Bencher) {
let flattened_keys = [
("type".to_string(), "m.text".to_string()),
("room_id".to_string(), "!room:server".to_string()),
("content.body".to_string(), "test message".to_string()),
(
"type".to_string(),
SimpleJsonValue::Str("m.text".to_string()),
),
(
"room_id".to_string(),
SimpleJsonValue::Str("!room:server".to_string()),
),
(
"content.body".to_string(),
SimpleJsonValue::Str("test message".to_string()),
),
]
.into_iter()
.collect();
@ -43,6 +53,7 @@ fn bench_match_exact(b: &mut Bencher) {
true,
vec![],
false,
false,
)
.unwrap();
@ -63,9 +74,18 @@ fn bench_match_exact(b: &mut Bencher) {
#[bench]
fn bench_match_word(b: &mut Bencher) {
let flattened_keys = [
("type".to_string(), "m.text".to_string()),
("room_id".to_string(), "!room:server".to_string()),
("content.body".to_string(), "test message".to_string()),
(
"type".to_string(),
SimpleJsonValue::Str("m.text".to_string()),
),
(
"room_id".to_string(),
SimpleJsonValue::Str("!room:server".to_string()),
),
(
"content.body".to_string(),
SimpleJsonValue::Str("test message".to_string()),
),
]
.into_iter()
.collect();
@ -82,6 +102,7 @@ fn bench_match_word(b: &mut Bencher) {
true,
vec![],
false,
false,
)
.unwrap();
@ -102,9 +123,18 @@ fn bench_match_word(b: &mut Bencher) {
#[bench]
fn bench_match_word_miss(b: &mut Bencher) {
let flattened_keys = [
("type".to_string(), "m.text".to_string()),
("room_id".to_string(), "!room:server".to_string()),
("content.body".to_string(), "test message".to_string()),
(
"type".to_string(),
SimpleJsonValue::Str("m.text".to_string()),
),
(
"room_id".to_string(),
SimpleJsonValue::Str("!room:server".to_string()),
),
(
"content.body".to_string(),
SimpleJsonValue::Str("test message".to_string()),
),
]
.into_iter()
.collect();
@ -121,6 +151,7 @@ fn bench_match_word_miss(b: &mut Bencher) {
true,
vec![],
false,
false,
)
.unwrap();
@ -141,9 +172,18 @@ fn bench_match_word_miss(b: &mut Bencher) {
#[bench]
fn bench_eval_message(b: &mut Bencher) {
let flattened_keys = [
("type".to_string(), "m.text".to_string()),
("room_id".to_string(), "!room:server".to_string()),
("content.body".to_string(), "test message".to_string()),
(
"type".to_string(),
SimpleJsonValue::Str("m.text".to_string()),
),
(
"room_id".to_string(),
SimpleJsonValue::Str("!room:server".to_string()),
),
(
"content.body".to_string(),
SimpleJsonValue::Str("test message".to_string()),
),
]
.into_iter()
.collect();
@ -160,6 +200,7 @@ fn bench_eval_message(b: &mut Bencher) {
true,
vec![],
false,
false,
)
.unwrap();