mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Tasks. Cancelling requests to slow task repositories.
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
package com.intellij.tasks;
|
||||
|
||||
import com.intellij.openapi.extensions.Extensions;
|
||||
import com.intellij.openapi.progress.ProgressIndicator;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.vcs.changes.LocalChangeList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -43,7 +44,12 @@ public abstract class TaskManager {
|
||||
|
||||
public abstract List<Task> getIssues(@Nullable String query, boolean forceRequest);
|
||||
|
||||
public abstract List<Task> getIssues(@Nullable String query, int max, long since, boolean forceRequest, final boolean withClosed);
|
||||
public abstract List<Task> getIssues(@Nullable String query,
|
||||
int max,
|
||||
long since,
|
||||
boolean forceRequest,
|
||||
final boolean withClosed,
|
||||
final ProgressIndicator cancelled);
|
||||
/**
|
||||
* Returns already cached issues.
|
||||
* @return cached issues.
|
||||
|
||||
@@ -15,11 +15,13 @@
|
||||
*/
|
||||
package com.intellij.tasks;
|
||||
|
||||
import com.intellij.openapi.progress.ProgressIndicator;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.util.xmlb.annotations.Attribute;
|
||||
import com.intellij.util.xmlb.annotations.Tag;
|
||||
import com.intellij.util.xmlb.annotations.Transient;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
@@ -83,6 +85,10 @@ public abstract class TaskRepository {
|
||||
*/
|
||||
public abstract Task[] getIssues(@Nullable String query, int max, long since) throws Exception;
|
||||
|
||||
public Task[] getIssues(@Nullable String query, int max, long since, @NotNull ProgressIndicator cancelled) throws Exception {
|
||||
return getIssues(query, max, since);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public abstract Task findTask(String id) throws Exception;
|
||||
|
||||
|
||||
@@ -84,8 +84,8 @@ public class GotoTaskAction extends GotoActionBase {
|
||||
if (!consumer.process(element)) return false;
|
||||
}
|
||||
|
||||
List<Task> tasks =
|
||||
TaskSearchSupport.getRepositoriesTasks(TaskManager.getManager(project), pattern, base.getMaximumListSizeLimit(), 0, true, everywhere);
|
||||
List<Task> tasks = TaskSearchSupport
|
||||
.getRepositoriesTasks(TaskManager.getManager(project), pattern, base.getMaximumListSizeLimit(), 0, true, everywhere, cancelled);
|
||||
tasks.removeAll(cachedAndLocalTasks);
|
||||
taskPsiElements = ContainerUtil.map(tasks, new Function<Task, TaskPsiElement>() {
|
||||
@Override
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.intellij.tasks.actions;
|
||||
|
||||
import com.intellij.openapi.progress.ProgressIndicator;
|
||||
import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.psi.codeStyle.NameUtil;
|
||||
import com.intellij.tasks.Task;
|
||||
@@ -59,8 +60,14 @@ public class TaskSearchSupport {
|
||||
});
|
||||
}
|
||||
|
||||
public static List<Task> getRepositoriesTasks(final TaskManager myManager, String pattern, int max, long since, boolean forceRequest, final boolean withClosed) {
|
||||
List<Task> tasks = myManager.getIssues(pattern, max, since, forceRequest, withClosed);
|
||||
public static List<Task> getRepositoriesTasks(final TaskManager myManager,
|
||||
String pattern,
|
||||
int max,
|
||||
long since,
|
||||
boolean forceRequest,
|
||||
final boolean withClosed,
|
||||
final ProgressIndicator cancelled) {
|
||||
List<Task> tasks = myManager.getIssues(pattern, max, since, forceRequest, withClosed, cancelled);
|
||||
ContainerUtil.sort(tasks, TaskManagerImpl.TASK_UPDATE_COMPARATOR);
|
||||
return tasks;
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.components.*;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.options.ShowSettingsUtil;
|
||||
import com.intellij.openapi.progress.EmptyProgressIndicator;
|
||||
import com.intellij.openapi.progress.ProcessCanceledException;
|
||||
import com.intellij.openapi.progress.ProgressIndicator;
|
||||
import com.intellij.openapi.progress.ProgressManager;
|
||||
@@ -231,14 +232,18 @@ public class TaskManagerImpl extends TaskManager implements ProjectComponent, Pe
|
||||
|
||||
@Override
|
||||
public List<Task> getIssues(@Nullable final String query, final boolean forceRequest) {
|
||||
return getIssues(query, 50, 0, forceRequest, true);
|
||||
return getIssues(query, 50, 0, forceRequest, true, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Task> getIssues(@Nullable String query, int max, long since, boolean forceRequest, final boolean withClosed) {
|
||||
List<Task> tasks = getIssuesFromRepositories(query, max, since, forceRequest);
|
||||
public List<Task> getIssues(@Nullable String query,
|
||||
int max,
|
||||
long since,
|
||||
boolean forceRequest,
|
||||
final boolean withClosed,
|
||||
final ProgressIndicator cancelled) {
|
||||
List<Task> tasks = getIssuesFromRepositories(query, max, since, forceRequest, cancelled);
|
||||
if (tasks == null) return getCachedIssues(withClosed);
|
||||
myIssueCache.putAll(ContainerUtil.newMapFromValues(tasks.iterator(), KEY_CONVERTOR));
|
||||
return ContainerUtil.filter(tasks, new Condition<Task>() {
|
||||
@Override
|
||||
public boolean value(final Task task) {
|
||||
@@ -651,7 +656,7 @@ public class TaskManagerImpl extends TaskManager implements ProjectComponent, Pe
|
||||
|
||||
private void doUpdate(@Nullable Runnable onComplete) {
|
||||
try {
|
||||
List<Task> issues = getIssuesFromRepositories(null, myConfig.updateIssuesCount, 0, false);
|
||||
List<Task> issues = getIssuesFromRepositories(null, myConfig.updateIssuesCount, 0, false, new EmptyProgressIndicator());
|
||||
if (issues == null) return;
|
||||
|
||||
synchronized (myIssueCache) {
|
||||
@@ -679,18 +684,25 @@ public class TaskManagerImpl extends TaskManager implements ProjectComponent, Pe
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private List<Task> getIssuesFromRepositories(@Nullable String request, int max, long since, boolean forceRequest) {
|
||||
private List<Task> getIssuesFromRepositories(@Nullable String request,
|
||||
int max,
|
||||
long since,
|
||||
boolean forceRequest,
|
||||
final ProgressIndicator cancelled) {
|
||||
List<Task> issues = null;
|
||||
for (final TaskRepository repository : getAllRepositories()) {
|
||||
if (!repository.isConfigured() || (!forceRequest && myBadRepositories.contains(repository))) {
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
final Task[] tasks = repository.getIssues(request, max, since);
|
||||
final Task[] tasks = repository.getIssues(request, max, since, cancelled);
|
||||
myBadRepositories.remove(repository);
|
||||
if (issues == null) issues = new ArrayList<Task>(tasks.length);
|
||||
ContainerUtil.addAll(issues, tasks);
|
||||
}
|
||||
catch (ProcessCanceledException ignored) {
|
||||
// OK
|
||||
}
|
||||
catch (Exception e) {
|
||||
//noinspection InstanceofCatchParameter
|
||||
if (e instanceof SocketTimeoutException) {
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.intellij.tasks.mantis;
|
||||
|
||||
import com.intellij.openapi.progress.EmptyProgressIndicator;
|
||||
import com.intellij.openapi.progress.ProgressIndicator;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.tasks.Comment;
|
||||
import com.intellij.tasks.Task;
|
||||
@@ -65,14 +67,23 @@ public class MantisRepository extends BaseRepositoryImpl {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Task[] getIssues(@Nullable String request, int max, long since) throws Exception {
|
||||
public Task[] getIssues(@Nullable String query, int max, long since) throws Exception {
|
||||
return getIssues(query, max, since, new EmptyProgressIndicator());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Task[] getIssues(@Nullable final String query,
|
||||
final int max,
|
||||
final long since,
|
||||
@NotNull final ProgressIndicator cancelled) throws Exception {
|
||||
MantisConnectPortType soap = createSoap();
|
||||
List<Task> tasks = new ArrayList<Task>(max);
|
||||
int page = 1;
|
||||
int issuesOnPage = StringUtils.isEmpty(request) ? max : max * request.length() * 5;
|
||||
int issuesOnPage = StringUtils.isEmpty(query) ? max : max * query.length() * 5;
|
||||
while (true) {
|
||||
cancelled.checkCanceled();
|
||||
final List<Task> issuesFromPage = getIssues(page, issuesOnPage, soap);
|
||||
final List<Task> filteredTasks = TaskSearchSupport.filterTasks(request != null ? request : "", issuesFromPage);
|
||||
final List<Task> filteredTasks = TaskSearchSupport.filterTasks(query != null ? query : "", issuesFromPage);
|
||||
tasks.addAll(filteredTasks);
|
||||
if (issuesFromPage.size() < issuesOnPage || tasks.size() >= max) {
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user