Commit graph

19 commits

Author SHA1 Message Date
J. Nick Koston
abf0c87e40
Migrate statistics to use timestamp columns () 2023-02-09 12:24:19 -06:00
Erik Montnemery
94519de8dd
Upgrade SQLAlchemy to 2.0.2 ()
Co-authored-by: J. Nick Koston <nick@koston.org>
2023-02-08 08:17:32 -06:00
epenet
a202588fd2
Add return type to json_loads ()
* Add JSON type definitions

* Sample use

* Keep mutable for a follo-up PR (avoid dead code)

* Use list/dict

* Remove JsonObjectType

* Remove reference to Union

* Cleanup

* Improve rest

* Rename json_dict => json_data

* Add docstring

* Add type hint to json_loads

* Add cast

* Move type alias to json helpers

* Cleanup

* Create and use json_loads_object

* Make error more explicit and add tests

* Use JsonObjectType in conversation

* Remove quotes
2023-02-07 17:21:55 +01:00
Marc Mueller
342b406dc0
Add Self typing (1) [mypy 1.0] () 2023-02-06 22:29:47 -06:00
J. Nick Koston
389fc515a1
Prevent overly large attributes from being stored in the database () 2023-02-02 11:49:33 -06:00
Erik Montnemery
53c5f02ca2
Remove some dead code from recorder () 2023-01-30 18:37:48 +01:00
J. Nick Koston
4e9bd09d39
Fix old indices not being removed in schema migration leading to slow MySQL queries ()
fixes 
2023-01-29 21:33:23 -05:00
Erik Montnemery
fea30c1ce9
Terminate strings at NUL when recording states and events () 2023-01-26 11:11:03 +01:00
J. Nick Koston
52ea64d1d0
Fix repr for States and Events without a timestamp () 2023-01-22 08:11:42 -10:00
J. Nick Koston
b8a1537b58
Improve performance of fetching and storing history and events with the database () 2023-01-02 13:26:08 -10:00
Franck Nijhof
94755a5773
String formatting and max line length - Part 4 ()
Co-authored-by: jjlawren <jjlawren@users.noreply.github.com>
2022-12-23 13:27:27 +01:00
Erik Montnemery
eca21ceff0
Make all datetime columns in recorder DB µs precision () 2022-10-19 10:26:17 +02:00
Erik Montnemery
2de273500e
Remove state_unit_of_measurement from metadata DB table ()
* Remove state_unit_of_measurement from metadata DB table

* Adjust test
2022-10-01 18:55:00 +02:00
Erik Montnemery
dd20a7ea62
Display statistics in the source's unit () 2022-09-15 12:01:24 -04:00
Erik Montnemery
eb28d7188b
Fix DB migration to schema version 29 ()
* Fix DB migration to schema version 29

* Fix misspelled constants
2022-09-09 08:06:14 +02:00
Marc Mueller
1a1eeb2274
Allow for subclass typing with StatisticsBase () 2022-07-20 04:02:03 +02:00
J. Nick Koston
8015bb98a9
Switch recorder and templates to use json helper ()
- These were using orjson directly, its a bit cleaner
  to use the helper so everything is easier to adjust
  in the future if we need to change anything about
  the loading
2022-06-23 14:32:26 +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
Erik Montnemery
5f2b4001f3
Separate recorder database schema from other classes ()
* 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