SES-3111 - Improve overall networking bottleneck (#855)

pull/1710/head
SessionHero01 4 months ago committed by GitHub
parent ac93336b5a
commit 58fc851eae
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -3,8 +3,11 @@ package org.thoughtcrime.securesms.dependencies
import android.content.Context
import dagger.Lazy
import dagger.hilt.android.qualifiers.ApplicationContext
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.channels.BufferOverflow
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.launch
import network.loki.messenger.libsession_util.ConfigBase
import network.loki.messenger.libsession_util.Contacts
import network.loki.messenger.libsession_util.ConversationVolatileConfig
@ -87,10 +90,9 @@ class ConfigFactory @Inject constructor(
private val userConfigs = HashMap<AccountId, Pair<ReentrantReadWriteLock, UserConfigsImpl>>()
private val groupConfigs = HashMap<AccountId, Pair<ReentrantReadWriteLock, GroupConfigsImpl>>()
private val _configUpdateNotifications = MutableSharedFlow<ConfigUpdateNotification>(
extraBufferCapacity = 100, // The notifications are normally important so we can afford to buffer a few
onBufferOverflow = BufferOverflow.SUSPEND
)
private val coroutineScope: CoroutineScope = GlobalScope
private val _configUpdateNotifications = MutableSharedFlow<ConfigUpdateNotification>()
override val configUpdateNotifications get() = _configUpdateNotifications
private fun requiresCurrentUserAccountId(): AccountId =
@ -152,9 +154,11 @@ class ConfigFactory @Inject constructor(
}
if (changed.isNotEmpty()) {
for (notification in changed) {
if (!_configUpdateNotifications.tryEmit(notification)) {
Log.e("ConfigFactory", "Unable to deliver config update notification")
coroutineScope.launch {
for (notification in changed) {
// Config change notifications are important so we must use suspend version of
// emit (not tryEmit)
_configUpdateNotifications.emit(notification)
}
}
}
@ -247,8 +251,10 @@ class ConfigFactory @Inject constructor(
}
if (changed) {
if (!_configUpdateNotifications.tryEmit(ConfigUpdateNotification.GroupConfigsUpdated(groupId))) {
Log.e("ConfigFactory", "Unable to deliver group update notification")
coroutineScope.launch {
// Config change notifications are important so we must use suspend version of
// emit (not tryEmit)
_configUpdateNotifications.emit(ConfigUpdateNotification.GroupConfigsUpdated(groupId))
}
}

@ -1,5 +1,6 @@
package org.session.libsession.snode
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import nl.komponents.kovenant.Deferred

@ -149,7 +149,7 @@ object HTTP {
}
@Suppress("OPT_IN_USAGE")
private val httpCallDispatcher = Dispatchers.IO.limitedParallelism(3)
private val httpCallDispatcher = Dispatchers.IO.limitedParallelism(15)
private suspend fun Call.await(): Response {
return withContext(httpCallDispatcher) {

Loading…
Cancel
Save