mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 12:17:07 +00:00
Speed up removing MQTT subscriptions (#118088)
This commit is contained in:
parent
ffcc9100a6
commit
ad638dbcc5
@ -429,10 +429,10 @@ class MQTT:
|
|||||||
self.config_entry = config_entry
|
self.config_entry = config_entry
|
||||||
self.conf = conf
|
self.conf = conf
|
||||||
|
|
||||||
self._simple_subscriptions: defaultdict[str, list[Subscription]] = defaultdict(
|
self._simple_subscriptions: defaultdict[str, set[Subscription]] = defaultdict(
|
||||||
list
|
set
|
||||||
)
|
)
|
||||||
self._wildcard_subscriptions: list[Subscription] = []
|
self._wildcard_subscriptions: set[Subscription] = set()
|
||||||
# _retained_topics prevents a Subscription from receiving a
|
# _retained_topics prevents a Subscription from receiving a
|
||||||
# retained message more than once per topic. This prevents flooding
|
# retained message more than once per topic. This prevents flooding
|
||||||
# already active subscribers when new subscribers subscribe to a topic
|
# already active subscribers when new subscribers subscribe to a topic
|
||||||
@ -789,9 +789,9 @@ class MQTT:
|
|||||||
The caller is responsible clearing the cache of _matching_subscriptions.
|
The caller is responsible clearing the cache of _matching_subscriptions.
|
||||||
"""
|
"""
|
||||||
if subscription.is_simple_match:
|
if subscription.is_simple_match:
|
||||||
self._simple_subscriptions[subscription.topic].append(subscription)
|
self._simple_subscriptions[subscription.topic].add(subscription)
|
||||||
else:
|
else:
|
||||||
self._wildcard_subscriptions.append(subscription)
|
self._wildcard_subscriptions.add(subscription)
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def _async_untrack_subscription(self, subscription: Subscription) -> None:
|
def _async_untrack_subscription(self, subscription: Subscription) -> None:
|
||||||
|
@ -529,16 +529,16 @@ async def test_non_unique_triggers(
|
|||||||
async_fire_mqtt_message(hass, "foobar/triggers/button1", "short_press")
|
async_fire_mqtt_message(hass, "foobar/triggers/button1", "short_press")
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert len(calls) == 2
|
assert len(calls) == 2
|
||||||
assert calls[0].data["some"] == "press1"
|
all_calls = {calls[0].data["some"], calls[1].data["some"]}
|
||||||
assert calls[1].data["some"] == "press2"
|
assert all_calls == {"press1", "press2"}
|
||||||
|
|
||||||
# Trigger second config references to same trigger
|
# Trigger second config references to same trigger
|
||||||
# and triggers both attached instances.
|
# and triggers both attached instances.
|
||||||
async_fire_mqtt_message(hass, "foobar/triggers/button2", "long_press")
|
async_fire_mqtt_message(hass, "foobar/triggers/button2", "long_press")
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert len(calls) == 2
|
assert len(calls) == 2
|
||||||
assert calls[0].data["some"] == "press1"
|
all_calls = {calls[0].data["some"], calls[1].data["some"]}
|
||||||
assert calls[1].data["some"] == "press2"
|
assert all_calls == {"press1", "press2"}
|
||||||
|
|
||||||
# Removing the first trigger will clean up
|
# Removing the first trigger will clean up
|
||||||
calls.clear()
|
calls.clear()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user