Use ulid_now instead of ulid_at_timestamp if no timestamp is passed (#104226)

* Use ulid_now instead of ulid_at_timestamp if no timestamp is passed

ulid_now is slightly faster than ulid_at_timestamp

* tweak usage
This commit is contained in:
J. Nick Koston 2023-11-19 21:27:24 -06:00 committed by GitHub
parent 6ef194f992
commit cc31d77205
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 27 additions and 16 deletions

View file

@ -91,7 +91,7 @@ from .util.async_ import (
from .util.json import JsonObjectType
from .util.read_only_dict import ReadOnlyDict
from .util.timeout import TimeoutManager
from .util.ulid import ulid, ulid_at_time
from .util.ulid import ulid_at_time, ulid_now
from .util.unit_system import (
_CONF_UNIT_SYSTEM_IMPERIAL,
_CONF_UNIT_SYSTEM_US_CUSTOMARY,
@ -930,7 +930,7 @@ class Context:
id: str | None = None, # pylint: disable=redefined-builtin
) -> None:
"""Init the context."""
self.id = id or ulid()
self.id = id or ulid_now()
self.user_id = user_id
self.parent_id = parent_id
self.origin_event: Event | None = None