Speed up ssdp domain matching (#124842)

* Speed up ssdp domain matching

Switch all() expression to dict.items() <= dict.items()

* rewrite as setcomp
This commit is contained in:
J. Nick Koston 2024-08-29 23:36:31 -10:00 committed by GitHub
parent 69a9aa4594
commit 6781a76de2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -284,16 +284,13 @@ class IntegrationMatchers:
def async_matching_domains(self, info_with_desc: CaseInsensitiveDict) -> set[str]:
"""Find domains matching the passed CaseInsensitiveDict."""
assert self._match_by_key is not None
domains = set()
for key, matchers_by_key in self._match_by_key.items():
if not (match_value := info_with_desc.get(key)):
continue
for domain, matcher in matchers_by_key.get(match_value, []):
if domain in domains:
continue
if all(info_with_desc.get(k) == v for (k, v) in matcher.items()):
domains.add(domain)
return domains
return {
domain
for key, matchers_by_key in self._match_by_key.items()
if (match_value := info_with_desc.get(key))
for domain, matcher in matchers_by_key.get(match_value, ())
if info_with_desc.items() >= matcher.items()
}
class Scanner: