[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
This commit is contained in:
Vyacheslav Moklev
2025-02-28 11:17:20 +02:00
committed by intellij-monorepo-bot
parent 0e4ea7d7ef
commit ad13cd0ee0

View File

@@ -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) {