Improve performance of fetching the state domain (#38653)

Pre calc domain when an entity id created to avoid
having to call the property method which had to call
split_entity_id every time. If there are a lot of
zone related automations, async_active_zone can call
async_entity_ids frequently which results in 100000s
of split_entity_id via the domain property every
second.
pull/38690/head
J. Nick Koston 2020-08-09 06:45:16 -05:00 committed by GitHub
parent ef8e74786f
commit a6f869aeee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 5 deletions

View File

@ -759,6 +759,7 @@ class State:
last_changed: last time the state was changed, not the attributes.
last_updated: last time this object was updated.
context: Context in which it was created
domain: Domain of this state.
"""
__slots__ = [
@ -768,6 +769,7 @@ class State:
"last_changed",
"last_updated",
"context",
"domain",
]
def __init__(
@ -801,11 +803,7 @@ class State:
self.last_updated = last_updated or dt_util.utcnow()
self.last_changed = last_changed or self.last_updated
self.context = context or Context()
@property
def domain(self) -> str:
"""Domain of this state."""
return split_entity_id(self.entity_id)[0]
self.domain = split_entity_id(self.entity_id)[0]
@property
def object_id(self) -> str: