From 62304b5a5c9ad1c991fa3621151c37d2b78a6255 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9E=97=E4=B8=87=E7=A8=8B?= <1498425439@qq.com> Date: Fri, 29 Dec 2023 19:53:26 +0800 Subject: [PATCH] fix(ConfCache): Load tsv ext doc in back to fix Slow ... EDT FilenameIndex.getAllFilesByExt(project, "tsv"); Slow operations are prohibited on EDT in 2023.3 --- .../plugin/show/ext/conf/ConfCache.java | 38 ++++++++++++------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/src/main/java/io/github/linwancen/plugin/show/ext/conf/ConfCache.java b/src/main/java/io/github/linwancen/plugin/show/ext/conf/ConfCache.java index e757f61..de260b1 100644 --- a/src/main/java/io/github/linwancen/plugin/show/ext/conf/ConfCache.java +++ b/src/main/java/io/github/linwancen/plugin/show/ext/conf/ConfCache.java @@ -2,6 +2,8 @@ package io.github.linwancen.plugin.show.ext.conf; 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; @@ -118,21 +120,29 @@ public class ConfCache { } public static void loadAll(@NotNull Project project) { - DumbService.getInstance(project).smartInvokeLater(() -> { - @NotNull Collection files = FilenameIndex.getAllFilesByExt(project, TsvLoader.EXT); - @NotNull StringBuilder sb = new StringBuilder(); - for (@NotNull VirtualFile file : files) { - load(file); - sb.append(file.getName()).append("\n"); + new Task.Backgroundable(project, "Show Load xxx.tree/key/doc/json.tsv") { + @Override + public void run(@NotNull ProgressIndicator indicator) { + ApplicationManager.getApplication().runReadAction(() -> { + @NotNull Collection files = FilenameIndex.getAllFilesByExt(project, TsvLoader.EXT); + @NotNull StringBuilder sb = new StringBuilder(); + int i = 0; + for (@NotNull VirtualFile file : files) { + indicator.setText(file.getName()); + load(file); + indicator.setFraction((double) ++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); + }); } - 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(); } public static void loadFile(@NotNull VirtualFile file, @Nullable Project project) {