Skip to content
Snippets Groups Projects
Unverified Commit 4bc19876 authored by J. Nick Koston's avatar J. Nick Koston Committed by GitHub
Browse files

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
parent 902d76da
No related branches found
No related tags found
No related merge requests found
......@@ -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:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment