From c926adca18c59816332ff22e62af4465179e35bc Mon Sep 17 00:00:00 2001 From: Rui <102453770+ruixhuang@users.noreply.github.com> Date: Thu, 24 Oct 2024 16:08:52 -0700 Subject: [PATCH] Reduce the unnecessary network reconnect (#732) --- .../state/v2/manager/AsyncAbacusStateManagerV2.kt | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/manager/AsyncAbacusStateManagerV2.kt b/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/manager/AsyncAbacusStateManagerV2.kt index bf635e7bc..2b7ecfea4 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/manager/AsyncAbacusStateManagerV2.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/manager/AsyncAbacusStateManagerV2.kt @@ -89,8 +89,8 @@ class AsyncAbacusStateManagerV2( private var environments: IList = iListOf() set(value) { - field = value - ioImplementations.threading?.async(ThreadingType.abacus) { + if (field != value) { + field = value _environment = findEnvironment(environmentId) ioImplementations.threading?.async(ThreadingType.main) { stateNotification?.environmentsChanged() @@ -117,8 +117,11 @@ class AsyncAbacusStateManagerV2( private var _environment: V4Environment? = null set(value) { if (field !== value) { + val shouldReconnect = field?.id != value?.id field = value - reconnect() + if (shouldReconnect) { + reconnect() + } } }