feat: improve dns cache performance by bdraco · Pull Request #1172 · python-zeroconf/python-zeroconf
Expand Up
@@ -134,14 +134,17 @@ def async_get_unique(self, entry: _UniqueRecordsType) -> Optional[DNSRecord]:
return None
return store.get(entry)
def async_all_by_details(self, name: str, type_: int, class_: int) -> Iterator[DNSRecord]: def async_all_by_details(self, name: _str, type_: int, class_: int) -> Iterator[DNSRecord]: """Gets all matching entries by details.
This function is not threadsafe and must be called from the event loop. """ key = name.lower() for entry in self.cache.get(key, []): records = self.cache.get(key) if records is None: return for entry in records: if _dns_record_matches(entry, key, type_, class_): yield entry
Expand All @@ -151,15 +154,15 @@ def async_entries_with_name(self, name: str) -> Dict[DNSRecord, DNSRecord]: This function is not threadsafe and must be called from the event loop. """ return self.cache.get(name.lower(), {}) return self.cache.get(name.lower()) or {}
def async_entries_with_server(self, name: str) -> Dict[DNSRecord, DNSRecord]: """Returns a dict of entries whose key matches the server.
This function is not threadsafe and must be called from the event loop. """ return self.service_cache.get(name.lower(), {}) return self.service_cache.get(name.lower()) or {}
# The below functions are threadsafe and do not need to be run in the # event loop, however they all make copies so they significantly Expand Down
def async_all_by_details(self, name: str, type_: int, class_: int) -> Iterator[DNSRecord]: def async_all_by_details(self, name: _str, type_: int, class_: int) -> Iterator[DNSRecord]: """Gets all matching entries by details.
This function is not threadsafe and must be called from the event loop. """ key = name.lower() for entry in self.cache.get(key, []): records = self.cache.get(key) if records is None: return for entry in records: if _dns_record_matches(entry, key, type_, class_): yield entry
Expand All @@ -151,15 +154,15 @@ def async_entries_with_name(self, name: str) -> Dict[DNSRecord, DNSRecord]: This function is not threadsafe and must be called from the event loop. """ return self.cache.get(name.lower(), {}) return self.cache.get(name.lower()) or {}
def async_entries_with_server(self, name: str) -> Dict[DNSRecord, DNSRecord]: """Returns a dict of entries whose key matches the server.
This function is not threadsafe and must be called from the event loop. """ return self.service_cache.get(name.lower(), {}) return self.service_cache.get(name.lower()) or {}
# The below functions are threadsafe and do not need to be run in the # event loop, however they all make copies so they significantly Expand Down