Skip to content

Justyns purge old data#2059

Merged
infamy merged 8 commits into
home-assistant:devfrom
infamy:justyns-purge_old_data
May 15, 2016
Merged

Justyns purge old data#2059
infamy merged 8 commits into
home-assistant:devfrom
infamy:justyns-purge_old_data

Conversation

@infamy
Copy link
Copy Markdown
Contributor

@infamy infamy commented May 13, 2016

Description: Auto purge data older the configured time on startup of hass.

Each time HASS starts, the recorder component will run _purge_old_data() before going into the event loop. _purge_old_data() will delete records from the events and states tables older than X days. After deleting those records, VACUUM is run on the database to free up disk space taken by the deleted records.

This also adds a purge_days config option to the history component. By default it is set to -1 which means no old records will be deleted.

Started by @justyns, this is just a clean up and some fixes to hopefully allow us to merge it soon.

Related issue (if applicable): #1681

Example entry for configuration.yaml (if applicable):

# Enables support for tracking state changes over time.
recorder:
  # Delete events and states older than 2 weeks
  purge_days: 14

Checklist:

If code communicates with devices:

  • Local tests with tox run successfully. Your PR cannot be merged unless tests pass
  • New dependencies have been added to the REQUIREMENTS variable (example).
  • New dependencies are only imported inside functions that use them (example).
  • New dependencies have been added to requirements_all.txt by running script/gen_requirements_all.py.
  • New files were added to .coveragerc.

If the code does not interact with devices:

  • Local tests with tox run successfully. Your PR cannot be merged unless tests pass
  • Tests have been added to verify that the new code works.

justyns and others added 6 commits April 15, 2016 19:54
Issue home-assistant#1337

When purge_days is set under the history component, recorder.py will
delete all events and states that are older than purge_days days ago.

Currently, this is only done once at start up.   A vacuum command is
also run to free up the disk space sqlite would still use after deleting
records.
CONF_PURGE_DAYS so it can be changed easier later.

Use 'recorder' domain instead of 'history' domain.

Pass purge_days config directly into Recorder object instead of passing
the config object around.
self.hass.stop()
recorder._INSTANCE.block_till_done()

def _add_test_states(self):
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

farcy v1.1

  • D401: First line should be in imperative mood ('Add', not 'Adds')

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

358 occurrences of add, 9 of adds. Our style seems to be more add then adds...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So its in the comment not the code.. fixed

@infamy
Copy link
Copy Markdown
Contributor Author

infamy commented May 14, 2016

Code clean up of #1681 which can be closed once this gets merged.

@infamy infamy merged commit ffbc99f into home-assistant:dev May 15, 2016
@justyns
Copy link
Copy Markdown
Contributor

justyns commented May 20, 2016

Thanks for finishing this up, @infamy!

@home-assistant home-assistant locked and limited conversation to collaborators Mar 17, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants