Skip to content

Commit

Permalink
feat: speed up adding and removing RecordUpdateListeners (#1253)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco committed Sep 3, 2023
1 parent 72d6886 commit 22e4a29
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/zeroconf/_core.py
Expand Up @@ -240,7 +240,7 @@ async def async_wait_for_start(self) -> None:
raise NotRunningException

@property
def listeners(self) -> List[RecordUpdateListener]:
def listeners(self) -> Set[RecordUpdateListener]:
return self.record_manager.listeners

async def async_wait(self, timeout: float) -> None:
Expand Down
7 changes: 6 additions & 1 deletion src/zeroconf/_handlers/record_manager.pxd
Expand Up @@ -12,11 +12,12 @@ cdef object RecordUpdate
cdef object TYPE_CHECKING
cdef object _TYPE_PTR


cdef class RecordManager:

cdef public object zc
cdef public DNSCache cache
cdef public cython.list listeners
cdef public cython.set listeners

cpdef async_updates(self, object now, object records)

Expand All @@ -29,3 +30,7 @@ cdef class RecordManager:
now_float=cython.float
)
cpdef async_updates_from_response(self, DNSIncoming msg)

cpdef async_add_listener(self, object listener, object question)

cpdef async_remove_listener(self, object listener)
4 changes: 2 additions & 2 deletions src/zeroconf/_handlers/record_manager.py
Expand Up @@ -45,7 +45,7 @@ def __init__(self, zeroconf: 'Zeroconf') -> None:
"""Init the record manager."""
self.zc = zeroconf
self.cache = zeroconf.cache
self.listeners: List[RecordUpdateListener] = []
self.listeners: Set[RecordUpdateListener] = set()

def async_updates(self, now: _float, records: List[RecordUpdate]) -> None:
"""Used to notify listeners of new information that has updated
Expand Down Expand Up @@ -175,7 +175,7 @@ def async_add_listener(
" In the future this will fail"
)

self.listeners.append(listener)
self.listeners.add(listener)

if question is None:
return
Expand Down
4 changes: 0 additions & 4 deletions src/zeroconf/_services/info.py
Expand Up @@ -758,10 +758,6 @@ def generate_request_query(
question.unicast = True
return out

def __eq__(self, other: object) -> bool:
"""Tests equality of service name"""
return isinstance(other, ServiceInfo) and other._name == self._name

def __repr__(self) -> str:
"""String representation"""
return '{}({})'.format(
Expand Down

0 comments on commit 22e4a29

Please sign in to comment.