:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
perf(flags): short-circuit array exact match in property_matching (#58068)
Patricio8d12f459aa31
diff --git a/rust/feature-flags/src/properties/property_matching.rs b/rust/feature-flags/src/properties/property_matching.rsindex 65c0df036fd9..ec231fa17d68 100644--- a/rust/feature-flags/src/properties/property_matching.rs+++ b/rust/feature-flags/src/properties/property_matching.rs@@ -107,13 +107,12 @@ pub fn match_property(}if value.is_array() {+ let target = to_string_representation(override_value).to_lowercase();return value.as_array().expect("expected array value").iter()- .map(|v| to_string_representation(v).to_lowercase())- .collect::<Vec<String>>()- .contains(&to_string_representation(override_value).to_lowercase());+ .any(|v| to_string_representation(v).to_lowercase() == target);}to_string_representation(value).to_lowercase()== to_string_representation(override_value).to_lowercase()@@ -667,6 +666,59 @@ mod test_match_properties {.is_err());}+ #[rstest::rstest]+ #[case("us", true)]+ #[case("Us", true)]+ #[case("US", true)]+ #[case("ca", true)]+ #[case("uk", true)]+ #[case("UK", true)]+ #[case("de", false)]+ fn test_match_properties_exact_array_is_case_insensitive(+ #[case] user_value: &str,+ #[case] expected: bool,+ ) {+ // Array Exact comparisons lowercase both sides, so a mixed-case filter+ // value must still match a lowercase user property and vice-versa.+ let property = PropertyFilter {+ key: "country".to_string(),+ value: Some(json!(["US", "CA", "Uk"])),+ operator: Some(OperatorType::Exact),+ prop_type: PropertyType::Person,+ group_type_index: None,+ negation: None,+ compiled_regex: None,+ };++ let actual = match_property(+ &property,+ &HashMap::from([("country".to_string(), json!(user_value))]),+ true,+ )+ .expect("expected match to exist");++ assert_eq!(actual, expected, "user_value = {user_value}");+ }++ #[test]+ fn test_match_properties_exact_empty_array_never_matches() {+ let property = PropertyFilter {+ key: "country".to_string(),+ value: Some(json!([])),+ operator: Some(OperatorType::Exact),+ prop_type: PropertyType::Person,+ group_type_index: None,+ negation: None,+ compiled_regex: None,+ };+ assert!(!match_property(+ &property,+ &HashMap::from([("country".to_string(), json!("us"))]),+ true+ )+ .expect("expected match to exist"));+ }+#[test]fn test_match_properties_is_not() {let property_a = PropertyFilter {