From c5e246530b4a796e0c09895e767b6873c68ad4e0 Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Sun, 13 Jan 2019 15:23:04 +0100 Subject: [PATCH] ComponentStore itself uses transactions to commit components and flush on disk (if VFS is used) --- .../src/ComponentStoreImpl.kt | 6 +++++- .../src/ProjectSaveSessionProducerManager.kt | 2 +- .../configuration-store-impl/src/ProjectStoreImpl.kt | 2 +- .../src/com/intellij/ide/SaveAndSyncHandlerImpl.kt | 11 ++--------- 4 files changed, 9 insertions(+), 12 deletions(-) diff --git a/platform/configuration-store-impl/src/ComponentStoreImpl.kt b/platform/configuration-store-impl/src/ComponentStoreImpl.kt index 146fd01c38af..3e84f9d6103d 100644 --- a/platform/configuration-store-impl/src/ComponentStoreImpl.kt +++ b/platform/configuration-store-impl/src/ComponentStoreImpl.kt @@ -138,7 +138,11 @@ abstract class ComponentStoreImpl : IComponentStore { internal abstract suspend fun doSave(result: SaveResult, isForceSavingAllSettings: Boolean) internal suspend fun createSaveSessionManagerAndSaveComponents(saveResult: SaveResult, isForceSavingAllSettings: Boolean): SaveSessionProducerManager { - return withContext(AppUIExecutor.onUiThread().coroutineDispatchingContext()) { + val uiExecutor = AppUIExecutor.onUiThread() + storageManager.componentManager?.let { + uiExecutor.inTransaction(it) + } + return withContext(uiExecutor.coroutineDispatchingContext()) { // todo should we call stopThreadPrioritizing? for some reasons stopThreadPrioritizing was not called by old code in ApplicationImpl/ProjectImpl save // probably because stopThreadPrioritizing is called on start write action (see ApplicationImpl.stopThreadPrioritizing) HeavyProcessLatch.INSTANCE.prioritizeUiActivity() diff --git a/platform/configuration-store-impl/src/ProjectSaveSessionProducerManager.kt b/platform/configuration-store-impl/src/ProjectSaveSessionProducerManager.kt index d877c0e28e1c..81f4da635374 100644 --- a/platform/configuration-store-impl/src/ProjectSaveSessionProducerManager.kt +++ b/platform/configuration-store-impl/src/ProjectSaveSessionProducerManager.kt @@ -24,7 +24,7 @@ internal class ProjectSaveSessionProducerManager(private val project: Project) : return SaveResult.EMPTY } - val saveResult = withContext(AppUIExecutor.onUiThread().inUndoTransparentAction().inWriteAction().coroutineDispatchingContext()) { + val saveResult = withContext(AppUIExecutor.onUiThread().inTransaction(project).inUndoTransparentAction().inWriteAction().coroutineDispatchingContext()) { val r = SaveResult() saveSessions(extraSessions, r) saveSessions(saveSessions, r) diff --git a/platform/configuration-store-impl/src/ProjectStoreImpl.kt b/platform/configuration-store-impl/src/ProjectStoreImpl.kt index 3d41d5370ea7..c9b1112f7106 100644 --- a/platform/configuration-store-impl/src/ProjectStoreImpl.kt +++ b/platform/configuration-store-impl/src/ProjectStoreImpl.kt @@ -363,7 +363,7 @@ private class ProjectWithModulesStoreImpl(project: Project, pathMacroManager: Pa return emptyList() } - return withContext(AppUIExecutor.onUiThread().coroutineDispatchingContext()) { + return withContext(AppUIExecutor.onUiThread().inTransaction(project).coroutineDispatchingContext()) { // do no create with capacity because very rarely a lot of modules will be modified val saveSessions: MutableList = SmartList() // commit components diff --git a/platform/platform-impl/src/com/intellij/ide/SaveAndSyncHandlerImpl.kt b/platform/platform-impl/src/com/intellij/ide/SaveAndSyncHandlerImpl.kt index 93311322bbf0..ced3c3749463 100644 --- a/platform/platform-impl/src/com/intellij/ide/SaveAndSyncHandlerImpl.kt +++ b/platform/platform-impl/src/com/intellij/ide/SaveAndSyncHandlerImpl.kt @@ -77,9 +77,7 @@ class SaveAndSyncHandlerImpl(private val settings: GeneralSettings) : SaveAndSyn } } else { - submitTransaction { - doSaveDocumentsAndProjectsAndAppInEdt() - } + doSaveDocumentsAndProjectsAndAppInEdt() } } @@ -179,13 +177,8 @@ class SaveAndSyncHandlerImpl(private val settings: GeneralSettings) : SaveAndSyn override fun refreshOpenFiles() { val files = ArrayList() - for (project in ProjectManager.getInstance().openProjects) { - for (file in FileEditorManager.getInstance(project).selectedFiles) { - if (file is NewVirtualFile) { - files.add(file) - } - } + FileEditorManager.getInstance(project).selectedFiles.filterTo(files) { it is NewVirtualFile } } if (!files.isEmpty()) {