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