refactor(repository)!: improve api caching and error handling (#2680)

Signed-off-by: James Rich <2199651+jamesarich@users.noreply.github.com>
This commit is contained in:
James Rich 2025-08-10 17:55:15 -05:00 committed by GitHub
parent 9bde1f6357
commit 07cdbacf8f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 161 additions and 86 deletions

View file

@ -264,7 +264,11 @@ constructor(
val deviceHardware =
actualNode.user.hwModel.number.let { deviceHardwareRepository.getDeviceHardwareByModel(it) }
_state.update { state ->
state.copy(node = actualNode, isLocal = destNum == ourNode, deviceHardware = deviceHardware)
state.copy(
node = actualNode,
isLocal = destNum == ourNode,
deviceHardware = deviceHardware.getOrNull(),
)
}
}
.launchIn(viewModelScope)

View file

@ -230,7 +230,9 @@ constructor(
val deviceHardware: StateFlow<DeviceHardware?> =
ourNodeInfo
.mapNotNull { nodeInfo ->
nodeInfo?.user?.hwModel?.let { deviceHardwareRepository.getDeviceHardwareByModel(it.number) }
nodeInfo?.user?.hwModel?.let {
deviceHardwareRepository.getDeviceHardwareByModel(it.number).getOrNull()
}
}
.stateIn(scope = viewModelScope, started = SharingStarted.WhileSubscribed(5_000), initialValue = null)