mirror of
https://github.com/home-assistant/core.git
synced 2025-04-24 09:17:53 +00:00
Small speed up to creating stats database rows (#124587)
* Small speed up to creating stats database rows Calling .timestamp() directly is faster on new cpython * more cleanup
This commit is contained in:
parent
902d76da36
commit
4bc19876ca
@ -693,13 +693,13 @@ class StatisticsBase:
|
||||
|
||||
@classmethod
|
||||
def from_stats(cls, metadata_id: int, stats: StatisticData) -> Self:
|
||||
"""Create object from a statistics with datatime objects."""
|
||||
"""Create object from a statistics with datetime objects."""
|
||||
return cls( # type: ignore[call-arg]
|
||||
metadata_id=metadata_id,
|
||||
created=None,
|
||||
created_ts=time.time(),
|
||||
start=None,
|
||||
start_ts=dt_util.utc_to_timestamp(stats["start"]),
|
||||
start_ts=stats["start"].timestamp(),
|
||||
mean=stats.get("mean"),
|
||||
min=stats.get("min"),
|
||||
max=stats.get("max"),
|
||||
|
@ -65,9 +65,7 @@ def process_datetime_to_timestamp(ts: datetime) -> float:
|
||||
|
||||
def datetime_to_timestamp_or_none(dt: datetime | None) -> float | None:
|
||||
"""Convert a datetime to a timestamp."""
|
||||
if dt is None:
|
||||
return None
|
||||
return dt_util.utc_to_timestamp(dt)
|
||||
return None if dt is None else dt.timestamp()
|
||||
|
||||
|
||||
def timestamp_to_datetime_or_none(ts: float | None) -> datetime | None:
|
||||
|
Loading…
x
Reference in New Issue
Block a user