ComponentStore itself uses transactions to commit components and flush on disk (if VFS is used)

This commit is contained in:
Vladimir Krivosheev
2019-01-14 08:11:24 +01:00
parent b99b742f41
commit c5e246530b
4 changed files with 9 additions and 12 deletions
@@ -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()
@@ -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)
@@ -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<SaveSession> = SmartList<SaveSession>()
// commit components
@@ -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<VirtualFile>()
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()) {