Skip to content
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

Avoid unecessary subscription while fetching user avatar #3281

Merged
merged 2 commits into from
Dec 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Sources/App/Settings/Eureka/AccountRow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ final class HomeAssistantAccountRow: Row<AccountCell>, RowType {

enum FetchAvatarError: Error, CancellableError {
case missingPerson
case missingURL
case missingURLForUserEntityPicture
case alreadySet
case couldntDecode

Expand All @@ -189,7 +189,7 @@ final class HomeAssistantAccountRow: Row<AccountCell>, RowType {
return
}

accountSubscription = api.connection.caches.user.subscribe { [weak self] _, user in
accountSubscription = api.connection.caches.user.once { [weak self] user in
guard let self else { return }
Current.Log.verbose("got user from user \(user)")
cachedUserName = user.name
Expand All @@ -202,7 +202,7 @@ final class HomeAssistantAccountRow: Row<AccountCell>, RowType {
}
}

avatarSubscription = api.connection.caches.states().subscribe { [weak self] _, states in
avatarSubscription = api.connection.caches.states().once { [weak self] states in
firstly { () -> Guarantee<Set<HAEntity>> in
Guarantee.value(states.all)
}.map { states throws -> HAEntity in
Expand All @@ -215,7 +215,7 @@ final class HomeAssistantAccountRow: Row<AccountCell>, RowType {
if let urlString = entity.attributes["entity_picture"] as? String {
return urlString
} else {
throw FetchAvatarError.missingURL
throw FetchAvatarError.missingURLForUserEntityPicture
}
}.map { path throws -> URL in
guard let url = server.info.connection.activeURL()?.appendingPathComponent(path) else {
Expand Down
Loading