mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 03:07:37 +00:00
Reduce space to store state_attributes and event_data for new MariaDB/MySQL databases (#91150)
Since MySQL and MariaDB support unsigned ints we can store the hashes in 4 bytes instead of 8 bytes
This commit is contained in:
parent
bd0378a961
commit
a62ede78ca
@ -143,6 +143,11 @@ class FAST_PYSQLITE_DATETIME(sqlite.DATETIME):
|
|||||||
return lambda value: None if value is None else ciso8601.parse_datetime(value)
|
return lambda value: None if value is None else ciso8601.parse_datetime(value)
|
||||||
|
|
||||||
|
|
||||||
|
# For MariaDB and MySQL we can use an unsigned integer type since it will fit 2**32
|
||||||
|
# for sqlite and postgresql we use a bigint
|
||||||
|
UINT_32_TYPE = BigInteger().with_variant(
|
||||||
|
mysql.INTEGER(unsigned=True), "mysql", "mariadb" # type: ignore[no-untyped-call]
|
||||||
|
)
|
||||||
JSON_VARIANT_CAST = Text().with_variant(
|
JSON_VARIANT_CAST = Text().with_variant(
|
||||||
postgresql.JSON(none_as_null=True), "postgresql" # type: ignore[no-untyped-call]
|
postgresql.JSON(none_as_null=True), "postgresql" # type: ignore[no-untyped-call]
|
||||||
)
|
)
|
||||||
@ -309,7 +314,7 @@ class EventData(Base):
|
|||||||
__table_args__ = (_DEFAULT_TABLE_ARGS,)
|
__table_args__ = (_DEFAULT_TABLE_ARGS,)
|
||||||
__tablename__ = TABLE_EVENT_DATA
|
__tablename__ = TABLE_EVENT_DATA
|
||||||
data_id: Mapped[int] = mapped_column(Integer, Identity(), primary_key=True)
|
data_id: Mapped[int] = mapped_column(Integer, Identity(), primary_key=True)
|
||||||
hash: Mapped[int | None] = mapped_column(BigInteger, index=True)
|
hash: Mapped[int | None] = mapped_column(UINT_32_TYPE, index=True)
|
||||||
# Note that this is not named attributes to avoid confusion with the states table
|
# Note that this is not named attributes to avoid confusion with the states table
|
||||||
shared_data: Mapped[str | None] = mapped_column(
|
shared_data: Mapped[str | None] = mapped_column(
|
||||||
Text().with_variant(mysql.LONGTEXT, "mysql", "mariadb")
|
Text().with_variant(mysql.LONGTEXT, "mysql", "mariadb")
|
||||||
@ -542,7 +547,7 @@ class StateAttributes(Base):
|
|||||||
__table_args__ = (_DEFAULT_TABLE_ARGS,)
|
__table_args__ = (_DEFAULT_TABLE_ARGS,)
|
||||||
__tablename__ = TABLE_STATE_ATTRIBUTES
|
__tablename__ = TABLE_STATE_ATTRIBUTES
|
||||||
attributes_id: Mapped[int] = mapped_column(Integer, Identity(), primary_key=True)
|
attributes_id: Mapped[int] = mapped_column(Integer, Identity(), primary_key=True)
|
||||||
hash: Mapped[int | None] = mapped_column(BigInteger, index=True)
|
hash: Mapped[int | None] = mapped_column(UINT_32_TYPE, index=True)
|
||||||
# Note that this is not named attributes to avoid confusion with the states table
|
# Note that this is not named attributes to avoid confusion with the states table
|
||||||
shared_attrs: Mapped[str | None] = mapped_column(
|
shared_attrs: Mapped[str | None] = mapped_column(
|
||||||
Text().with_variant(mysql.LONGTEXT, "mysql", "mariadb")
|
Text().with_variant(mysql.LONGTEXT, "mysql", "mariadb")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user