Skip to content

Setup recorder model relationships to avoid calling flush#40467

Merged
balloob merged 2 commits intohome-assistant:devfrom
bdraco:recorder_flush
Sep 30, 2020
Merged

Setup recorder model relationships to avoid calling flush#40467
balloob merged 2 commits intohome-assistant:devfrom
bdraco:recorder_flush

Conversation

@bdraco
Copy link
Copy Markdown
Member

@bdraco bdraco commented Sep 22, 2020

Proposed change

Setup recorder model relationships to avoid calling flush

When old_state_id was added, flush was now done after each
state changed event. This turned out to be more expensive
than expected and can be avoided with relationships.

In the py-spy provided in #40292 the two flames on the left
are calls to flush

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Example entry for configuration.yaml:

# Example configuration.yaml

Additional information

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • The code has been formatted using Black (black --fast homeassistant tests)
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • Untested files have been added to .coveragerc.

The integration reached or maintains the following Integration Quality Scale:

  • No score or internal
  • 🥈 Silver
  • 🥇 Gold
  • 🏆 Platinum

To help with the load of incoming pull requests:

@bdraco
Copy link
Copy Markdown
Member Author

bdraco commented Sep 22, 2020

Opened #40468 for the flapping logbook test

When old_state_id was added, flush was now done after each
state changed event. This turned out to be more expensive
than expected and can be avoided with relationships.
@balloob balloob merged commit d9ba32d into home-assistant:dev Sep 30, 2020
bdraco added a commit that referenced this pull request Nov 28, 2020
…t from under the recorder (#43610)

* MariaDB doesn't purge #42402

This addresses  #42402
Relationships within table "states" and between tables "states" and "events " #40467 prevent the purge from working correctly. The database increases w/o any purge.
This proposal sets related indices to NULL and permits deleting of rows.
Further explanations can be found here #42402
This proposal also allows to purge the tables "events" and "states" in any order.

* Update models.py

Corrected for Black style requirements

* Update homeassistant/components/recorder/models.py

Co-authored-by: J. Nick Koston <nick@koston.org>

* Add the options to foreign key constraints

* purge old states when database gets deleted out from under us

* pylint

Co-authored-by: J. Nick Koston <nick@koston.org>
rccoleman pushed a commit to rccoleman/core that referenced this pull request Dec 4, 2020
…t from under the recorder (home-assistant#43610)

* MariaDB doesn't purge home-assistant#42402

This addresses  home-assistant#42402
Relationships within table "states" and between tables "states" and "events " home-assistant#40467 prevent the purge from working correctly. The database increases w/o any purge.
This proposal sets related indices to NULL and permits deleting of rows.
Further explanations can be found here home-assistant#42402
This proposal also allows to purge the tables "events" and "states" in any order.

* Update models.py

Corrected for Black style requirements

* Update homeassistant/components/recorder/models.py

Co-authored-by: J. Nick Koston <nick@koston.org>

* Add the options to foreign key constraints

* purge old states when database gets deleted out from under us

* pylint

Co-authored-by: J. Nick Koston <nick@koston.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Logbook tests are not reliable Higher CPU continues in 0.118

3 participants