Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Reduce freeze in ProjectUpdater #7153

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -37,7 +37,6 @@
import com.google.idea.blaze.qsync.project.ProjectPath;
import com.google.idea.blaze.qsync.project.ProjectProto;
import com.google.idea.blaze.qsync.project.ProjectProto.LibrarySource;
import com.google.idea.common.util.Transactions;
import com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProvider;
import com.intellij.openapi.externalSystem.service.project.ProjectDataManager;
import com.intellij.openapi.module.Module;
@@ -116,7 +115,7 @@ public void onNewProjectSnapshot(Context<?> context, QuerySyncProjectSnapshot gr

private void updateProjectModel(ProjectProto.Project spec, Context<?> context) {
File imlDirectory = new File(BlazeDataStorage.getProjectDataDir(importSettings), "modules");
Transactions.submitWriteActionTransactionAndWait(
ThreadingUtils.Companion.readWriteAction(
() -> {
IdeModifiableModelsProvider models =
ProjectDataManager.getInstance().createModifiableModelsProvider(project);
@@ -217,9 +216,10 @@ private void updateProjectModel(ProjectProto.Project spec, Context<?> context) {
.build(),
workspaceLanguageSettings);
}
models.commit();

}
});
return models;
}, models -> models.commit());
}

private Library getOrCreateLibrary(
22 changes: 22 additions & 0 deletions base/src/com/google/idea/blaze/base/qsync/ThreadingUtils.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.google.idea.blaze.base.qsync

import com.intellij.openapi.application.readAndWriteAction
import kotlinx.coroutines.runBlocking
import java.util.concurrent.Callable
import java.util.function.Consumer


class ThreadingUtils {
companion object {
fun <T> readWriteAction(readPart: Callable<T>, commit: Consumer<T>) {
runBlocking {
readAndWriteAction {
var ret = readPart.call()
writeAction {
commit.accept(ret);
}
}
}
}
}
}