Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Verified Commit d548fd32 authored by Fahim M. Choudhury's avatar Fahim M. Choudhury
Browse files

perf: parallelize CleanAPK detail fetches

Run per-package detail requests concurrently to shorten update list retrieval for multiple packages.
parent fb6bdf34
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -22,6 +22,9 @@ import foundation.e.apps.data.StoreRepository
import foundation.e.apps.data.application.data.Application
import foundation.e.apps.data.cleanapk.data.categories.Categories
import foundation.e.apps.data.cleanapk.data.search.Search
import kotlinx.coroutines.async
import kotlinx.coroutines.awaitAll
import kotlinx.coroutines.coroutineScope
import retrofit2.Response

const val NUMBER_OF_ITEMS = 20
@@ -33,6 +36,10 @@ interface CleanApkRepository : StoreRepository {
    suspend fun checkAvailablePackages(packageNames: List<String>): Response<Search>

    suspend fun getAppDetailsForPackages(packageNames: List<String>): List<Application> {
        return packageNames.map { getAppDetails(it) }
        return coroutineScope {
            packageNames.map {
                async { getAppDetails(it) }
            }.awaitAll()
        }
    }
}