diff --git a/app/build.gradle b/app/build.gradle index e1f07867b0..3577205d5d 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -12,8 +12,8 @@ android { applicationId "org.ole.planet.myplanet" minSdk = 26 targetSdk = 36 - versionCode = 5362 - versionName = "0.53.62" + versionCode = 5363 + versionName = "0.53.63" ndkVersion = '26.3.11579264' vectorDrawables.useSupportLibrary = true } diff --git a/app/src/main/java/org/ole/planet/myplanet/services/UploadManager.kt b/app/src/main/java/org/ole/planet/myplanet/services/UploadManager.kt index 49a0c4ad8d..2175dafac4 100644 --- a/app/src/main/java/org/ole/planet/myplanet/services/UploadManager.kt +++ b/app/src/main/java/org/ole/planet/myplanet/services/UploadManager.kt @@ -12,8 +12,13 @@ import java.io.IOException import javax.inject.Inject import javax.inject.Singleton import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.async +import kotlinx.coroutines.awaitAll import kotlinx.coroutines.launch import kotlinx.coroutines.withContext +import kotlinx.coroutines.coroutineScope +import kotlinx.coroutines.sync.Semaphore +import kotlinx.coroutines.sync.withPermit import okhttp3.MediaType.Companion.toMediaTypeOrNull import okhttp3.RequestBody.Companion.toRequestBody import org.ole.planet.myplanet.MainApplication @@ -456,16 +461,26 @@ class UploadManager @Inject constructor( activitiesToUpload.chunked(BATCH_SIZE).forEach { batch -> val successfulUpdates = mutableMapOf() - batch.forEach { activityData -> - try { - val `object` = apiInterface.postDoc( - UrlUtils.header, "application/json", - "${UrlUtils.getUrl()}/login_activities", activityData.serialized - ).body() - - successfulUpdates[activityData.id] = `object` - } catch (e: java.io.IOException) { - Log.e(TAG, "Exception in UploadManager", e) + val semaphore = Semaphore(6) + coroutineScope { + val deferreds = batch.map { activityData -> + async { + try { + val `object` = semaphore.withPermit { + apiInterface.postDoc( + UrlUtils.header, "application/json", + "${UrlUtils.getUrl()}/login_activities", activityData.serialized + ).body() + } + activityData.id to `object` + } catch (e: java.io.IOException) { + Log.e(TAG, "Exception in UploadManager", e) + null + } + } + } + deferreds.awaitAll().filterNotNull().forEach { (id, obj) -> + successfulUpdates[id] = obj } }