Serialize websocket event message once (#40453)

Since most of the json serialize work for the websocket was done
multiple times for the same message, we can avoid the overhead
of serializing the same message many times (once per websocket
client) with a cache.
This commit is contained in:
J. Nick Koston authored and GitHub committed 2020-09-22 08:47:04 -05:00
1 parent d82b97fbe1
commit f0f817c361
5 files changed
+120 -32

No files matched your search

+5
View File
@@ -548,6 +548,11 @@ class Event:
self.time_fired = time_fired or dt_util.utcnow()
self.context: Context = context or Context()
def __hash__(self) -> int:
"""Make hashable."""
# The only event type that shares context are the TIME_CHANGED
return hash((self.event_type, self.context.id, self.time_fired))
def as_dict(self) -> Dict:
"""Create a dict representation of this Event.