-
Notifications
You must be signed in to change notification settings - Fork 413
Remove hiddenBy and disabledBy from HAAppEntity and DB #4265
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Eliminates the hiddenBy and disabledBy properties from HAAppEntity, related database tables, and query logic. Entity hidden/disabled state is now determined dynamically from AppEntityRegistry, simplifying entity state management and reducing data duplication.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Removes the hiddenBy and disabledBy fields from HAAppEntity and its backing database table, and shifts hidden/disabled resolution to AppEntityRegistry to avoid duplicated state.
Changes:
- Deleted
hiddenBy/disabledByfromHAAppEntityand removed the corresponding DB columns and enum cases. - Updated hidden/disabled evaluation to be derived from
AppEntityRegistryand adjustedHAAppEntity.config(include:)filtering accordingly. - Removed the now-unneeded entity DB synchronization logic in
AreasServiceand updated home entity observation to no longer filter on removed columns.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| Sources/Shared/HAAppEntity.swift | Removes persisted hidden/disabled fields; derives hidden/disabled dynamically and updates config filtering logic. |
| Sources/Shared/Database/Tables/HAppEntityTable.swift | Drops hiddenBy/disabledBy columns from the HAAppEntity table schema. |
| Sources/Shared/Database/DatabaseTables.swift | Removes hiddenBy/disabledBy enum cases for the AppEntity table. |
| Sources/Shared/AreasService.swift | Removes logic that previously synced hidden/disabled state into HAAppEntity rows. |
| Sources/App/WebView/ExperimentalSpace/Home/HomeViewModel.swift | Removes DB filters on removed columns when observing app entities. |
## Summary Addresses performance feedback on #4265. The `config(include:)` method was using `first(where:)` to search the entire registry array for each entity, resulting in O(n²) complexity. Replaced with dictionary-based lookups for O(1) access. **Changes:** - Build registry dictionary keyed by `(serverId, entityId)` tuples - Replace `first(where:)` array search with direct dictionary access - Use `uniquingKeysWith` to handle potential duplicate keys gracefully **Before:** ```swift guard let registry = appEntityRegistry .first(where: { $0.entityId == entity.entityId && $0.serverId == entity.serverId }) else { return true } ``` **After:** ```swift let registryDict = Dictionary( appEntityRegistry.compactMap { registry -> ((String, String), AppEntityRegistry)? in guard let entityId = registry.entityId else { return nil } return ((registry.serverId, entityId), registry) }, uniquingKeysWith: { first, _ in first } ) guard let registry = registryDict[(entity.serverId, entity.entityId)] else { return true } ``` ## Screenshots N/A - Backend performance optimization ## Link to pull request in Documentation repository Documentation: home-assistant/companion.home-assistant# ## Any other notes This is a stacked PR merging into #4265. <!-- START COPILOT CODING AGENT TIPS --> --- 💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more [Copilot coding agent tips](https://gh.io/copilot-coding-agent-tips) in the docs. --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: bgoncal <5808343+bgoncal@users.noreply.github.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4265 +/- ##
=======================================
Coverage ? 43.08%
=======================================
Files ? 261
Lines ? 15106
Branches ? 0
=======================================
Hits ? 6508
Misses ? 8598
Partials ? 0 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Eliminates the hiddenBy and disabledBy properties from HAAppEntity, related database tables, and query logic. Entity hidden/disabled state is now determined dynamically from AppEntityRegistry, simplifying entity state management and reducing data duplication.
Summary
Screenshots
Link to pull request in Documentation repository
Documentation: home-assistant/companion.home-assistant#
Any other notes