perf(ReadAction): use nonBlocking and runReadActionInSmartMode

This commit is contained in:
林万程
2024-01-21 16:18:47 +08:00
parent fadd45ddd3
commit 3e34fa8ac9
5 changed files with 78 additions and 64 deletions

View File

@@ -4,6 +4,7 @@ import com.intellij.ide.projectView.ProjectView;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.progress.Task;
import com.intellij.openapi.project.DumbService;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.search.FilenameIndex;
@@ -127,25 +128,27 @@ public class ConfCache {
@Override
public void run(@NotNull ProgressIndicator indicator) {
indicator.setIndeterminate(false);
ApplicationManager.getApplication().runReadAction(() -> {
@NotNull Collection<VirtualFile> files = FilenameIndex.getAllFilesByExt(project, TsvLoader.EXT);
@NotNull StringBuilder sb = new StringBuilder();
double i = 0;
for (@NotNull VirtualFile file : files) {
indicator.setText(file.getName());
load(file);
i++;
indicator.setFraction(i / files.size());
sb.append(file.getName()).append("\n");
}
if (files.isEmpty()) {
return;
}
if (!project.isDisposed()) {
ProjectView.getInstance(project).refresh();
}
LOG.info("Ext doc conf load all complete {} files\n{}", files.size(), sb);
});
DumbService.getInstance(project).runReadActionInSmartMode(() ->
ApplicationManager.getApplication().runReadAction(() -> {
@NotNull Collection<VirtualFile> files = FilenameIndex.getAllFilesByExt(project,
TsvLoader.EXT);
@NotNull StringBuilder sb = new StringBuilder();
double i = 0;
for (@NotNull VirtualFile file : files) {
indicator.setText(file.getName());
load(file);
i++;
indicator.setFraction(i / files.size());
sb.append(file.getName()).append("\n");
}
if (files.isEmpty()) {
return;
}
if (!project.isDisposed()) {
ProjectView.getInstance(project).refresh();
}
LOG.info("Ext doc conf load all complete {} files\n{}", files.size(), sb);
}));
}
}.queue();
}