Implement debounced writes for HACS data stores#5293
Draft
ludeeus wants to merge 4 commits into
Draft
Conversation
The HA Update entity flow (`update.async_install` → `repository.async_download_repository` → `_async_post_install`) never called `async_write`, so updates only landed on disk when the next unrelated websocket action fired or when `EVENT_HOMEASSISTANT_FINAL_WRITE` ran at shutdown. On Docker installs the container is often killed without a graceful stop and the event never fires, so HACS forgets it had updated the repository. Schedule a debounced write at the end of `_async_post_install` via `Store.async_delay_save` so every install path persists, while bursts (bulk updates, queued installs) coalesce into a single disk write per store. HA's Store also flushes pending delayed saves on shutdown for free, so the existing `EVENT_HOMEASSISTANT_FINAL_WRITE` safety net stays as belt-and-braces. Refactor `HacsData` to use pure sync builders for the three store payloads (`hacs`, `data`, `repositories`) so both the eager `async_write` path and the new `async_schedule_write` path share the same assembly logic without relying on a mutable `self.content` side-effect.
Contributor
There was a problem hiding this comment.
Pull request overview
Refactors HACS data persistence to support debounced writes via a new async_delay_save_to_store() helper and a HacsData.async_schedule_write() method, with data-building logic extracted into pure _build_* callbacks. Repository post-install now triggers a scheduled write instead of relying on the caller to flush immediately.
Changes:
- Add
async_delay_save_to_store()wrapper aroundStore.async_delay_saveinutils/store.py. - Split
HacsDatawrite path into pure_build_hacs_data/_build_repositories_data/_build_experimental_dataand rename per-repo helpers to_repository_export/_experimental_repository_export; addasync_schedule_write(). - Call
self.hacs.data.async_schedule_write()at the end of_async_post_install.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| custom_components/hacs/utils/store.py | New async_delay_save_to_store helper that delegates to Store.async_delay_save on a store fetched via get_store_for_key. |
| custom_components/hacs/utils/data.py | Refactors data export to pure builders and introduces async_schedule_write using the new delayed-save helper. |
| custom_components/hacs/repositories/base.py | Schedules a debounced data write after post-install steps complete. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.