chore: refactor · python-zeroconf/python-zeroconf@e7efb1a

@@ -86,10 +86,8 @@ def _async_add(self, record: _DNSRecord) -> bool:

8686

# replaces any existing records that are __eq__ to each other which

8787

# removes the risk that accessing the cache from the wrong

8888

# direction would return the old incorrect entry.

89-

if record.key not in self.cache:

89+

if (store := self.cache.get(record.key)) is None:

9090

store = self.cache[record.key] = {}

91-

else:

92-

store = self.cache[record.key]

9391

new = record not in store and not isinstance(record, DNSNsec)

9492

store[record] = record

9593

when = record.created + (record.ttl * 1000)

@@ -100,10 +98,8 @@ def _async_add(self, record: _DNSRecord) -> bool:

1009810199

if isinstance(record, DNSService):

102100

service_record = record

103-

if service_record.server_key not in self.service_cache:

101+

if (service_store := self.service_cache.get(service_record.server_key)) is None:

104102

service_store = self.service_cache[service_record.server_key] = {}

105-

else:

106-

service_store = self.service_cache[service_record.server_key]

107103

service_store[service_record] = service_record

108104

return new

109105