data: make sure fetch preselected models in the same order of their IDs
This commit is contained in:
parent
2b70887725
commit
36c3768f52
|
|
@ -86,25 +86,24 @@ class HuggingFaceRemoteDataSourceImpl @Inject constructor(
|
|||
parallelCount: Int,
|
||||
quorum: Float,
|
||||
): List<HuggingFaceModelDetails> = withContext(Dispatchers.IO) {
|
||||
val successes = mutableListOf<HuggingFaceModelDetails>()
|
||||
val failures = mutableListOf<Throwable>()
|
||||
|
||||
val sem = Semaphore(parallelCount)
|
||||
supervisorScope {
|
||||
val results = supervisorScope {
|
||||
ids.map { id ->
|
||||
async {
|
||||
sem.withPermit {
|
||||
runCatching { getModelDetails(id) }
|
||||
.onSuccess { synchronized(successes) { successes += it } }
|
||||
.onFailure { t ->
|
||||
if (t is CancellationException) throw t
|
||||
synchronized(failures) { failures += t }
|
||||
}
|
||||
try {
|
||||
Result.success(getModelDetails(id))
|
||||
} catch (t: CancellationException) {
|
||||
Result.failure(t)
|
||||
}
|
||||
}
|
||||
}
|
||||
}.awaitAll()
|
||||
}
|
||||
|
||||
val successes = results.mapNotNull { it.getOrNull() }
|
||||
val failures = results.mapNotNull { it.exceptionOrNull() }
|
||||
|
||||
val total = ids.size
|
||||
val failed = failures.size
|
||||
val ok = successes.size
|
||||
|
|
|
|||
|
|
@ -190,7 +190,7 @@ class ModelsManagementViewModel @Inject constructor(
|
|||
val models = modelRepository.fetchPreselectedHuggingFaceModels().map(HuggingFaceModelDetails::toModel)
|
||||
_managementState.emit(Download.Ready(models))
|
||||
} catch (_: CancellationException) {
|
||||
// no-op
|
||||
resetManagementState()
|
||||
} catch (_: UnknownHostException) {
|
||||
_managementState.value = Download.Error(message = "No internet connection")
|
||||
} catch (_: SocketTimeoutException) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue