1
0
mirror of https://github.com/home-assistant/core.git synced 2025-06-29 17:37:07 +00:00

27 Commits

Author SHA1 Message Date
J. Nick Koston
2ec1359063
Dynamically size recorder max backlog based on available memory ()
Co-authored-by: Franck Nijhof <git@frenck.dev>
2023-04-18 12:35:49 +02:00
J. Nick Koston
d49fbc17df
Fix recorder attribute excludes not being effective until after startup ()
* Fix attribute excludes not being effective until after startup

fixes 

* reduce
2023-03-23 20:52:37 -04:00
J. Nick Koston
b1f64de6ce
Remove the old ix_states_event_id index if its no longer being used ()
* Remove the old ix_states_event_id index if its no longer being used

* cover it

* fixes

* fixup

* Update homeassistant/components/recorder/tasks.py
2023-03-17 20:27:33 -04:00
J. Nick Koston
377dff5ee4
Ensure all recorder session executes use retries or the execute helper () 2023-03-17 10:45:58 -10:00
J. Nick Koston
c2b770bcb9
Load pending state attributes and event data ids at startup ()
* Load pending state attributes and event data ids at startup

Since we queue all events to be processed after startup
we can have a thundering herd of queries to prime the
LRUs of event data and state attributes ids. Since we
know we are about to process a chunk of events we can
fetch all the ids in two queries

* lru

* fix hang

* Fix recorder LRU being destroyed if event session is reopened

We would clear the LRU in _close_event_session but
it would never get replaced with an LRU again so
it would leak memory if the event session is reopened

* Fix recorder LRU being destroyed if event session is reopened

We would clear the LRU in _close_event_session but
it would never get replaced with an LRU again so
it would leak memory if the event session is reopened

* cleanup
2023-02-19 21:26:38 -05:00
J. Nick Koston
fb55933b0a
Reduce chance of queue overflow during schema migration ()
Co-authored-by: Franck Nijhof <git@frenck.dev>
2023-02-01 18:34:40 +01:00
Erik Montnemery
b94e1e9ef8
Fire events when long term statistics is updated ()
* Fire events when long term statistics is updated

* Allow the new events to be subscribed to by anyone

* Address review comments

* Finish renaming events

* Finish renaming events

* Fix do_adhoc_statistics

* Adjust tests

* Adjust tests
2022-11-24 22:01:36 +01:00
Erik Montnemery
9aa6043255
Set character set to utf8mb4 when connecting to MySQL or MariaDB databases () 2022-10-11 14:01:46 +02:00
J. Nick Koston
8b067e83f7
Initial orjson support take 3 ()
* Initial orjson support take 2

Still need to work out problem building wheels

--

Redux of  /  Now possible since the following is solved:
 (comment)

This implements orjson where we use our default encoder.  This does not implement orjson where `ExtendedJSONEncoder` is used as these areas tend to be called far less frequently.  If its desired, this could be done in a followup, but it seemed like a case of diminishing returns (except maybe for large diagnostics files, or traces, but those are not expected to be downloaded frequently).

Areas where this makes a perceptible difference:
- Anything that subscribes to entities (Initial subscribe_entities payload)
- Initial download of registries on first connection / restore
- History queries
- Saving states to the database
- Large logbook queries
- Anything that subscribes to events (appdaemon)

Cavets:
orjson supports serializing dataclasses natively (and much faster) which
eliminates the need to implement `as_dict` in many places
when the data is already in a dataclass. This works
well as long as all the data in the dataclass can also
be serialized. I audited all places where we have an `as_dict`
for a dataclass and found only backups needs to be adjusted (support for `Path` needed to be added for backups).  I was a little bit worried about `SensorExtraStoredData` with `Decimal` but it all seems to work out from since it converts it before it gets to the json encoding cc @dgomes

If it turns out to be a problem we can disable this
with option |= [orjson.OPT_PASSTHROUGH_DATACLASS](https://github.com/ijl/orjson#opt_passthrough_dataclass) and it
will fallback to `as_dict`

Its quite impressive for history queries
<img width="1271" alt="Screen_Shot_2022-05-30_at_23_46_30" src="https://user-images.githubusercontent.com/663432/171145699-661ad9db-d91d-4b2d-9c1a-9d7866c03a73.png">

* use for views as well

* handle UnicodeEncodeError

* tweak

* DRY

* DRY

* not needed

* fix tests

* Update tests/components/http/test_view.py

* Update tests/components/http/test_view.py

* black

* templates
2022-06-22 21:59:51 +02:00
J. Nick Koston
c365454afb
Revert "Initial orjson support ()" ()
This was causing the wheels to fail to build. We need
to workout why when we don't have release pressure

This reverts commit d9d22a95563c745ce6a50095f7de902eb078805d.
2022-05-31 13:51:55 -07:00
J. Nick Koston
d9d22a9556
Initial orjson support () 2022-05-31 12:18:11 -07:00
J. Nick Koston
a8f1dda004
Use ciso8601 for parsing MySQLdb datetimes ()
* Use ciso8601 for parsing MySQLDB datetimes

The default parser is this:

5340191feb/MySQLdb/times.py (L66)

* tweak

* tweak

* add coverage for building the MySQLdb connect conv param
2022-05-13 19:26:09 -05:00
J. Nick Koston
a8aa0e1cca
Add Estimated Database Size to the recorder system health () 2022-05-07 21:02:54 -07:00
J. Nick Koston
29bda196b5
Break apart recorder into tasks and core modules () 2022-05-02 21:53:56 -07:00
J. Nick Koston
37d39ac6d3
Add restored to the set of attributes excluded from being recorded in the db ()
* Add restored to the set of attributes excluded from being recorded in the database

- Noticed on restart that the table gets 100s of new rows because
  of these

* Update homeassistant/components/recorder/const.py
2022-04-16 23:09:08 +02:00
J. Nick Koston
c85387290a
Increase recorder queue max backlog to 40k, improve message () 2022-04-14 11:45:07 -10:00
J. Nick Koston
522a9bb6b1
Exclude supported features and attribution from being recorded in the database () 2022-04-03 13:51:42 +02:00
J. Nick Koston
0c0df07c52
Avoid hashing attributes when they are already in the cache () 2022-03-19 23:33:37 -07:00
J. Nick Koston
bc862e97ed
Use a dedicated executor pool for database operations ()
Co-authored-by: Erik Montnemery <erik@montnemery.com>
Co-authored-by: Franck Nijhof <git@frenck.dev>
2022-03-17 23:09:01 -10:00
Erik Montnemery
4c5aca93df
Add recorder status WS API ()
* Add recorder status WS API

* Rename recorder/status to recorder/info

* Silence pylint

* Improve tests

* Address review comments

* Tweak

* Try to fix tests

* Try to debug flaky tests

* Try to fix tests

* Revert changes to async_migration_in_progress

* Try to fix tests

* Remove debug prints

* Apply suggestions from code review
2021-11-04 16:46:45 +01:00
J. Nick Koston
0099b54489
Fix recorder purge with sqlite3 < 3.32.0 () 2021-07-12 22:03:13 +02:00
J. Nick Koston
a060acc2b1
Fix recorder with MSSQL ()
Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
2021-03-09 11:16:19 -10:00
J. Nick Koston
557684c3ce
Add ability to disable the sqlite3 quick_check () 2020-09-02 10:12:56 +02:00
Pascal Vizeli
c291d4aa7d
Intelligent timeout handler for setup/bootstrap ()
Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
Co-authored-by: J. Nick Koston <nick@koston.org>
2020-08-05 14:58:19 +02:00
J. Nick Koston
1acdb28cdd
Automatically recover when the sqlite3 database is malformed or corrupted ()
* Validate sqlite database on startup and move away if corruption is detected.

* do not switch context in test -- its all sync
2020-07-17 19:07:37 -10:00
Paulus Schoutsen
4de97abc3a Black 2019-07-31 12:25:30 -07:00
Paulus Schoutsen
61909e873f Feature/reorg recorder ()
* Re-organize recorder

* Fix history

* Fix history stats

* Fix restore state

* Lint

* Fix session reconfigure

* Move imports around

* Do not start recording till HASS started

* Lint

* Fix logbook

* Fix race condition recorder init

* Better reporting on errors
2017-02-26 14:38:06 -08:00