Store JSON in database in compact format (#53364)

* Store JSON in database in compact format

* Fix logbook
This commit is contained in:
Franck Nijhof 2021-07-23 00:05:59 +02:00 committed by GitHub
parent 12503d548b
commit c875ff8648
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 7 deletions

View file

@ -48,11 +48,10 @@ from homeassistant.helpers.integration_platform import (
from homeassistant.loader import bind_hass
import homeassistant.util.dt as dt_util
ENTITY_ID_JSON_TEMPLATE = '"entity_id": "{}"'
ENTITY_ID_JSON_EXTRACT = re.compile('"entity_id": "([^"]+)"')
DOMAIN_JSON_EXTRACT = re.compile('"domain": "([^"]+)"')
ICON_JSON_EXTRACT = re.compile('"icon": "([^"]+)"')
ENTITY_ID_JSON_TEMPLATE = '"entity_id": ?"{}"'
ENTITY_ID_JSON_EXTRACT = re.compile('"entity_id": ?"([^"]+)"')
DOMAIN_JSON_EXTRACT = re.compile('"domain": ?"([^"]+)"')
ICON_JSON_EXTRACT = re.compile('"icon": ?"([^"]+)"')
ATTR_MESSAGE = "message"
CONTINUOUS_DOMAINS = ["proximity", "sensor"]

View file

@ -101,7 +101,8 @@ class Events(Base): # type: ignore
"""Create an event database object from a native event."""
return Events(
event_type=event.event_type,
event_data=event_data or json.dumps(event.data, cls=JSONEncoder),
event_data=event_data
or json.dumps(event.data, cls=JSONEncoder, separators=(",", ":")),
origin=str(event.origin.value),
time_fired=event.time_fired,
context_id=event.context.id,
@ -184,7 +185,9 @@ class States(Base): # type: ignore
else:
dbstate.domain = state.domain
dbstate.state = state.state
dbstate.attributes = json.dumps(dict(state.attributes), cls=JSONEncoder)
dbstate.attributes = json.dumps(
dict(state.attributes), cls=JSONEncoder, separators=(",", ":")
)
dbstate.last_changed = state.last_changed
dbstate.last_updated = state.last_updated