Skip to content

Commit

Permalink
Add extra logging for database updates (#3185)
Browse files Browse the repository at this point in the history
<!-- Thank you for submitting a Pull Request and helping to improve Home
Assistant. Please complete the following sections to help the processing
and review of your changes. Please do not delete anything from this
template. -->

## Summary
<!-- Provide a brief summary of the changes you have made and most
importantly what they aim to achieve -->

## Screenshots
<!-- If this is a user-facing change not in the frontend, please include
screenshots in light and dark mode. -->

## Link to pull request in Documentation repository
<!-- Pull requests that add, change or remove functionality must have a
corresponding pull request in the Companion App Documentation repository
(https://github.com/home-assistant/companion.home-assistant). Please add
the number of this pull request after the "#" -->
Documentation: home-assistant/companion.home-assistant#

## Any other notes
<!-- If there is any other information of note, like if this Pull
Request is part of a bigger change, please include it here. -->
  • Loading branch information
bgoncal authored Nov 22, 2024
1 parent ee8386b commit b1c3d89
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions Sources/Shared/API/Models/AppEntitiesModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,19 @@ public final class AppEntitiesModel: AppEntitiesModelProtocol {
// First check for time to avoid unecessary filtering to check count
if !checkLastDatabaseUpdateLessThanMinuteAgo() {
let appRelatedEntities = filterDomains(entities)
Current.Log
.verbose(
"Updating App Entities for \(server.info.name) checkLastDatabaseUpdateLessThanMinuteAgo false, lastDatabaseUpdate \(String(describing: lastDatabaseUpdate)) "
)
updateLastUpdate(entitiesCount: appRelatedEntities.count)
handle(appRelatedEntities: appRelatedEntities, server: server)
} else {
let appRelatedEntities = filterDomains(entities)
if lastEntitiesCount != appRelatedEntities.count {
Current.Log
.verbose(
"Updating App Entities for \(server.info.name) entities count diff, count: last \(lastEntitiesCount), new \(appRelatedEntities.count)"
)
updateLastUpdate(entitiesCount: appRelatedEntities.count)
handle(appRelatedEntities: appRelatedEntities, server: server)
}
Expand Down Expand Up @@ -71,6 +79,10 @@ public final class AppEntitiesModel: AppEntitiesModelProtocol {
.fetchAll(db)
}
if appEntities != cachedEntities {
Current.Log
.verbose(
"Updating App Entities for \(server.info.name), cached entities were different than new entities"
)
try Current.database.write { db in
try HAAppEntity.deleteAll(db, ids: cachedEntities.map(\.id))
for entity in appEntities {
Expand Down

0 comments on commit b1c3d89

Please sign in to comment.