From 258ed1a3449dab9ac37ccda8d320381a708763d0 Mon Sep 17 00:00:00 2001 From: Peter Gromov Date: Wed, 4 Dec 2019 08:15:41 +0100 Subject: [PATCH] UsageViewImpl: use ReadAction.nonBlocking GitOrigin-RevId: 80d9ec0385037ad6130bbd604fe21d1f95964fe7 --- .../intellij/usages/impl/UsageViewImpl.java | 45 +++++-------------- 1 file changed, 12 insertions(+), 33 deletions(-) diff --git a/platform/usageView/src/com/intellij/usages/impl/UsageViewImpl.java b/platform/usageView/src/com/intellij/usages/impl/UsageViewImpl.java index da93397eef3a..1021cac3151f 100644 --- a/platform/usageView/src/com/intellij/usages/impl/UsageViewImpl.java +++ b/platform/usageView/src/com/intellij/usages/impl/UsageViewImpl.java @@ -11,11 +11,11 @@ import com.intellij.openapi.Disposable; import com.intellij.openapi.actionSystem.*; import com.intellij.openapi.actionSystem.ex.ActionUtil; import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.application.ModalityState; import com.intellij.openapi.application.ReadAction; import com.intellij.openapi.command.CommandProcessor; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.progress.ProgressIndicator; -import com.intellij.openapi.progress.util.ProgressIndicatorUtils; import com.intellij.openapi.progress.util.ProgressWrapper; import com.intellij.openapi.project.DumbService; import com.intellij.openapi.project.IndexNotReadyException; @@ -1312,40 +1312,19 @@ public class UsageViewImpl implements UsageViewEx { private void queueUpdateBulk(@NotNull List toUpdate, @NotNull Runnable onCompletedInEdt) { if (toUpdate.isEmpty()) return; - addUpdateRequest(() -> { - for (Node node : toUpdate) { - try { - if (isDisposed()) break; - if (!runReadActionWithRetries(() -> node.update(this, edtNodeChangedQueue))) { - ApplicationManager.getApplication().invokeLater(() -> queueUpdateBulk(toUpdate, onCompletedInEdt)); - return; + ReadAction + .nonBlocking(() -> { + for (Node node : toUpdate) { + try { + node.update(this, edtNodeChangedQueue); + } + catch (IndexNotReadyException ignore) { } } - catch (IndexNotReadyException ignore) { - } - } - ApplicationManager.getApplication().invokeLater(onCompletedInEdt); - }); - } - - private boolean runReadActionWithRetries(@NotNull Runnable r) { - if (ApplicationManager.getApplication().isDispatchThread()) { - r.run(); - return true; - } - - final int MAX_RETRIES = 5; - for (int i = 0; i < MAX_RETRIES; i++) { - if (isDisposed()) { - return true; - } - - if (ProgressIndicatorUtils.runInReadActionWithWriteActionPriority(r)) { - return true; - } - ProgressIndicatorUtils.yieldToPendingWriteActions(); - } - return false; + }) + .expireWith(this) + .finishOnUiThread(ModalityState.defaultModalityState(), __ -> onCompletedInEdt.run()) + .submit(updateRequests); } private void updateImmediatelyNodesUpToRoot(@NotNull Collection nodes) {