feat: small improvements to ServiceBrowser performance (#1283) · python-zeroconf/python-zeroconf@0fc031b

@@ -404,24 +404,26 @@ def async_update_records(self, zc: 'Zeroconf', now: float_, records: List[Record

404404

This method will be run in the event loop.

405405

"""

406406

for record_update in records:

407-

record, old_record = record_update

407+

record = record_update[0]

408+

old_record = record_update[1]

408409

record_type = record.type

409410410411

if record_type is _TYPE_PTR:

411412

if TYPE_CHECKING:

412413

record = cast(DNSPointer, record)

413-

for type_ in self.types.intersection(cached_possible_types(record.name)):

414+

pointer = record

415+

for type_ in self.types.intersection(cached_possible_types(pointer.name)):

414416

if old_record is None:

415-

self._enqueue_callback(SERVICE_STATE_CHANGE_ADDED, type_, record.alias)

416-

elif record.is_expired(now):

417-

self._enqueue_callback(SERVICE_STATE_CHANGE_REMOVED, type_, record.alias)

417+

self._enqueue_callback(SERVICE_STATE_CHANGE_ADDED, type_, pointer.alias)

418+

elif pointer.is_expired(now):

419+

self._enqueue_callback(SERVICE_STATE_CHANGE_REMOVED, type_, pointer.alias)

418420

else:

419-

expire_time = record.get_expiration_time(_EXPIRE_REFRESH_TIME_PERCENT)

421+

expire_time = pointer.get_expiration_time(_EXPIRE_REFRESH_TIME_PERCENT)

420422

self.reschedule_type(type_, now, expire_time)

421423

continue

422424423425

# If its expired or already exists in the cache it cannot be updated.

424-

if old_record or record.is_expired(now):

426+

if old_record or record.is_expired(now) is True:

425427

continue

426428427429

if record_type in _ADDRESS_RECORD_TYPES: