101 Commits

Author SHA1 Message Date
Marc Mueller
f822fd82bb
Fix recorder fixture typing (#136174) 2025-01-21 18:18:05 -10:00
Erik Montnemery
bb7abd037c
Revert "Revert "Improve recorder history queries (#131702)"" (#133561)
Revert "Revert "Improve recorder history queries (#131702)" (#133203)"

This reverts commit 74e4654c26177909e653921f27f838fd1366adc0.
2024-12-19 11:50:12 +01:00
Erik Montnemery
74e4654c26
Revert "Improve recorder history queries (#131702)" (#133203) 2024-12-15 12:28:32 +01:00
Erik Montnemery
552613d949
Remove support for live recorder data migration of event type IDs (#131826) 2024-12-06 21:08:08 +01:00
Erik Montnemery
bbce183faf
Deprecate dt_util.utc_to_timestamp (#131787) 2024-11-28 17:00:20 +01:00
Erik Montnemery
381d5453b1
Improve recorder history queries (#131702)
* Improve recorder history queries

* Remove some comments

* Update StatesManager._oldest_ts when adding pending state

* Update after review

* Improve tests

* Improve post-purge logic

* Avoid calling dt_util.utc_to_timestamp in new code

---------

Co-authored-by: J. Nick Koston <nick@koston.org>
2024-11-27 21:12:42 +01:00
Erik Montnemery
44f90dca0c
Fix logic for purge of recorder runs (#130378)
* Fix logic for purge of recorder runs

* Make test more explicit

* Explicitly don't remove unclosed recorder runs in purge
2024-11-26 07:47:47 +01:00
Davin Kevin
f42386de44
Prevent endless loop in recorder when using a filter and there are no more states to purge (#126149)
Co-authored-by: J. Nick Koston <nick@koston.org>
2024-11-21 20:50:49 +01:00
epenet
c76d68503a
Add missing hass type hint in history and recorder tests (#124204) 2024-08-19 15:41:09 +02:00
Erik Montnemery
1f2c54f112
Avoid nesting sessions in recorder purge tests (#122581) 2024-07-25 13:12:10 +02:00
J. Nick Koston
73f6e3c07b
Narrow sqlite database corruption check to ensure disk image is malformed (#121947)
* Narrow sqlite database corruption check to ensure disk image is malformed

The database corruption check would also replace the database when it
locked externally instead of only when its malformed.

This was discovered in https://github.com/home-assistant/core/issues/121909#issuecomment-2227409124
when a user did a manual index creation while HA was online

* tweak

* tweak

* fix

* fix
2024-07-14 23:23:07 +02:00
Erik Montnemery
6df15ad8fc
Drop use of async_setup_recorder_instance fixture in recorder purge tests (#121193) 2024-07-04 10:39:24 -05:00
Erik Montnemery
408e524551
Add recorder test fixture for skipping tests by DB engine (#121118)
* Add recorder test fixture for skipping tests by DB engine

* Fix mistake
2024-07-04 00:02:46 +02:00
Marc Mueller
f11b316dac
Import Generator from collections.abc (4) (#120917) 2024-07-01 11:54:42 +02:00
Marc Mueller
837ee7c4fb
Import Generator from typing_extensions (4) (#118992) 2024-06-06 17:41:37 +02:00
epenet
b54a68750b
Add type hints for FixtureRequest in tests (#118779) 2024-06-04 10:37:54 +02:00
karwosts
2ac44f6083
Make recorder.purge_entities require at least one entity filter value (#110066)
Co-authored-by: J. Nick Koston <nick@koston.org>
2024-04-22 20:10:18 +02:00
Joost Lekkerkerker
6bb4e7d62c
Bump ruff to 0.3.4 (#112690)
Co-authored-by: Sid <27780930+autinerd@users.noreply.github.com>
Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
Co-authored-by: J. Nick Koston <nick@koston.org>
2024-03-26 00:02:16 +01:00
Sid
00ec7f11f0
Enable Ruff rule PT007 (#113764)
Co-authored-by: Franck Nijhof <frenck@frenck.nl>
2024-03-19 09:01:07 +01:00
Marc Mueller
7d6251ca08
Add empty line after module docstring [tests q-s] (#112711) 2024-03-08 14:47:22 +01:00
J. Nick Koston
67e6febde4
Ensure the purge entities service cleans up the states_meta table (#109344) 2024-02-02 09:32:17 +01:00
Aarni Koskela
706add4a57
Switch formatting from black to ruff-format (#102893)
Co-authored-by: Franck Nijhof <git@frenck.dev>
2023-11-27 14:38:59 +01:00
J. Nick Koston
27b5a9e074
Reduce number of test states in big purge test to fix CI (#102401) 2023-10-20 08:09:59 -10:00
J. Nick Koston
da1d5fc862
Increase max bind vars based on database version (#101464) 2023-10-06 07:59:38 +02:00
J. Nick Koston
88893121a1
Increase timeout for test_purge_many_old_events (#93579) 2023-05-25 22:38:44 -05:00
J. Nick Koston
9dcd73b308
Update recorder tests to avoid patching utcnow (#93489) 2023-05-24 17:47:42 -05:00
J. Nick Koston
ce3cb5864a
Improve reliablity of recorder purge test (#92641) 2023-05-07 01:28:43 +02:00
J. Nick Koston
6e628d2f06
Add a negative cache to the recorder event type manager (#91770) 2023-04-22 14:09:04 +02:00
J. Nick Koston
49079691d4
Reduce overhead of legacy database columns on new installs (#90246)
* Reduce overhead of legacy database columns on new installs

* Reduce overhead of legacy database columns on new installs

* Reduce overhead of legacy database columns on new installs

* Reduce overhead of legacy database columns on new installs

* not working as expected

* override the type compiler

* override the type compiler

* override the type compiler

* override the type compiler

* Apply suggestions from code review

* pgsql char1

* make entity filter test setup with old schema

* fix some more tests that were mutating state

* fix some more tests that were mutating state

* fix some more tests that were mutating state

* fix more dbstate mutations

* add shim for older tests

* split migration tests

* add coverage for purging legacy data

* tweak

* more fixes

* drop some legacy

* fix another test

* fix a few more

* add casts for postgresql in case someone deletes the schema changes table

* dry

* dry

* dry
2023-04-10 10:08:46 -04:00
J. Nick Koston
d0d4ab6056
Require a list of entity ids when fetching history (#90992) 2023-04-08 16:14:44 -10:00
J. Nick Koston
aebe4c66a6
Fix cpu thrashing during purge after all legacy events were removed (#89923)
* Fix cpu thrashing during purge after all legacy events were removed

We now remove the the index of of event ids on the states table when its
all NULLs to save space. The purge path needs to avoid checking for legacy
rows to purge if the index has been removed since it will result in a full
table scan each purge cycle that will always find no legacy rows to purge

* one more place

* drop the key constraint as well

* fixes

* more sqlite
2023-03-19 22:04:24 -04:00
J. Nick Koston
99d6b1fa57
Migrate States to use a table manager (#89769) 2023-03-15 16:19:43 -10:00
J. Nick Koston
aec2d63302
Add keep_days to recorder.purge_entities (#89726) 2023-03-15 11:13:47 -10:00
J. Nick Koston
a244749712
Make StatesMetaManager thread-safe when an entity_id is fully deleted from the database and than re-added (#89732)
* refactor to make StatesMetaManager threadsafe

* refactor to make StatesMetaManager threadsafe

* refactor to make StatesMetaManager threadsafe

* refactor to make StatesMetaManager threadsafe

* reduce

* comments
2023-03-15 08:54:02 -04:00
J. Nick Koston
b906d67c1e
Fix filtered purge not removing newer events (#89721) 2023-03-14 16:33:19 -10:00
J. Nick Koston
c41f91be89
Deduplicate entity_id in the states table (#89557) 2023-03-12 10:01:58 -10:00
J. Nick Koston
8bd43760b6
Deduplicate event_types in the events table (#89465)
* Deduplicate event_types in the events table

* Deduplicate event_types in the events table

* more fixes

* adjust

* adjust

* fix product

* fix tests

* adjust

* migrate

* migrate

* migrate

* more test fixes

* more test fixes

* fix

* migration test

* adjust

* speed up

* fix index

* fix more tests

* handle db failure

* preload

* tweak

* adjust

* fix stale docs strings, remove dead code

* refactor

* fix slow tests

* coverage

* self join to resolve query performance

* fix typo

* no need for quiet

* no need to drop index already dropped

* remove index that will never be used

* drop index sooner as we no longer use it

* Revert "remove index that will never be used"

This reverts commit 461aad2c52d7d6c2c6ca1df4cb30b77c52027d46.

* typo
2023-03-11 14:54:55 -05:00
J. Nick Koston
1bd9767d8c
Handle InnoDB deadlocks during migration (#89073)
* Handle slow InnoDB rollback when encountering duplicates during migration

fixes #89069

* adjust

* fix mock

* tests

* return on success
2023-03-03 22:00:13 -05:00
J. Nick Koston
c2b770bcb9
Load pending state attributes and event data ids at startup (#88444)
* 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
epenet
185cd61cbd
Add type hints to integration tests (recorder) (#88313) 2023-02-17 18:50:09 +01:00
epenet
efef915fc7
Add mariadb 10.3.32 to database tests (#87741)
Co-authored-by: J. Nick Koston <nick@koston.org>
2023-02-13 16:28:39 -06:00
J. Nick Koston
abf0c87e40
Migrate statistics to use timestamp columns (#87321) 2023-02-09 12:24:19 -06:00
Erik Montnemery
720f51657d
Add CI job which runs recorder tests on PostgreSQL (#80614)
Co-authored-by: Franck Nijhof <git@frenck.dev>
Co-authored-by: J. Nick Koston <nick@koston.org>
2023-02-07 09:46:14 -06:00
J. Nick Koston
b8a1537b58
Improve performance of fetching and storing history and events with the database (#84870) 2023-01-02 13:26:08 -10:00
Erik Montnemery
f4951a4f31
Add CI job which runs recorder tests on MariaDB (#80586)
Co-authored-by: Franck Nijhof <git@frenck.dev>
2022-10-19 13:04:28 +02:00
Erik Montnemery
31a787558f
Ensure recorder test fixture is setup before hass fixture (#80528)
* Ensure recorder test fixture is setup before hass fixture

* Adjust more tests
2022-10-19 07:58:47 +02:00
Erik Montnemery
5f2b4001f3
Separate recorder database schema from other classes (#72977)
* Separate recorder database schema from other classes

* fix logbook imports

* migrate new tests

* few more

* last one

* fix merge

Co-authored-by: J. Nick Koston <nick@koston.org>
2022-06-07 14:41:43 +02:00
J. Nick Koston
d8b0376942
Fix purge of legacy database events that are not state changed (#72815) 2022-06-01 11:56:06 +02:00
J. Nick Koston
a70e2a33dc
Fixing purging legacy rows and improve performance (#71916) 2022-05-15 21:25:07 -07:00
J. Nick Koston
a8aa0e1cca
Add Estimated Database Size to the recorder system health (#71463) 2022-05-07 21:02:54 -07:00