From ad13cd0ee091b7e2280564b4547276eba2d7e85d Mon Sep 17 00:00:00 2001 From: Vyacheslav Moklev Date: Fri, 28 Feb 2025 11:17:20 +0200 Subject: [PATCH] [RDCT] IJPL-170114: Add an ability to save settings components under a foreign clientId Sometimes there is a need to save settings under a remote clientId. This wasn't possible before, because in `ComponentStoreImpl#commitComponents` an original component for the Host clientId was always taken. This commit fixes that, getting a correct component for per-client components under a remote clientId. (cherry picked from commit d2da4442de6dacbaa704bb59386b9fc94f655a1a) GitOrigin-RevId: f36a55f42675879abbc5c3806e1e508711fb13ac --- .../src/ComponentStoreImpl.kt | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/platform/configuration-store-impl/src/ComponentStoreImpl.kt b/platform/configuration-store-impl/src/ComponentStoreImpl.kt index c6acffeb1092..d187e4f2082f 100644 --- a/platform/configuration-store-impl/src/ComponentStoreImpl.kt +++ b/platform/configuration-store-impl/src/ComponentStoreImpl.kt @@ -230,6 +230,20 @@ abstract class ComponentStoreImpl : IComponentStore { saveSessionManager.save(saveResult) } + private fun getClientAwareComponentInfo(name: String): ComponentInfo? { + val info = components.get(name) ?: return null + if (info.stateSpec?.perClient != true || ClientId.isCurrentlyUnderLocalId) + return info + + val componentManager = storageManager.componentManager ?: application + val componentClass = info.component.javaClass + val clientComponent = componentManager.getService(componentClass) + if (clientComponent == null || clientComponent === info.component) + return info + + return ComponentInfoImpl(info.pluginId, clientComponent, info.stateSpec) + } + internal open suspend fun commitComponents(isForce: Boolean, sessionManager: SaveSessionProducerManager, saveResult: SaveResult) { val names = ArrayUtilRt.toStringArray(components.keys) if (names.isEmpty()) { @@ -248,7 +262,7 @@ abstract class ComponentStoreImpl : IComponentStore { for (name in names) { val start = System.currentTimeMillis() try { - val info = components.get(name) ?: continue + val info = getClientAwareComponentInfo(name) ?: continue var currentModificationCount = -1L if (info.lastSaved != -1) {