mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
schedule update in dumb mode once requestRebuild was called. Previously, requestRebuild only marked need for rebuild and index access causes rebuild to start.
This commit is contained in:
@@ -122,7 +122,6 @@ public class FileBasedIndexImpl extends FileBasedIndex {
|
||||
|
||||
private static final int OK = 1;
|
||||
private static final int REQUIRES_REBUILD = 2;
|
||||
private static final int REBUILD_IN_PROGRESS = 3;
|
||||
private static final Map<ID<?, ?>, AtomicInteger> ourRebuildStatus = new THashMap<ID<?, ?>, AtomicInteger>();
|
||||
|
||||
private final MessageBusConnection myConnection;
|
||||
@@ -679,7 +678,9 @@ public class FileBasedIndexImpl extends FileBasedIndex {
|
||||
for (ID<?, ?> indexId : myIndices.keySet()) {
|
||||
final UpdatableIndex<?, ?, FileContent> index = getIndex(indexId);
|
||||
assert index != null;
|
||||
checkRebuild(indexId, true); // if the index was scheduled for rebuild, only clean it
|
||||
if(ourRebuildStatus.get(indexId).get() != OK) {
|
||||
doClearIndex(indexId); // if the index was scheduled for rebuild, only clean it
|
||||
}
|
||||
index.dispose();
|
||||
}
|
||||
|
||||
@@ -825,7 +826,9 @@ public class FileBasedIndexImpl extends FileBasedIndex {
|
||||
myChangedFilesCollector.tryToEnsureAllInvalidateTasksCompleted();
|
||||
if (isUpToDateCheckEnabled()) {
|
||||
try {
|
||||
checkRebuild(indexId, false);
|
||||
if (ourRebuildStatus.get(indexId).get() != OK) {
|
||||
throw new ProcessCanceledException();
|
||||
}
|
||||
myChangedFilesCollector.forceUpdate(project, filter, restrictedFile);
|
||||
indexUnsavedDocuments(indexId, project, filter, restrictedFile);
|
||||
}
|
||||
@@ -1225,65 +1228,6 @@ public class FileBasedIndexImpl extends FileBasedIndex {
|
||||
@Override
|
||||
public <K> void scheduleRebuild(@NotNull final ID<K, ?> indexId, @NotNull final Throwable e) {
|
||||
requestRebuild(indexId, new Throwable(e));
|
||||
try {
|
||||
checkRebuild(indexId, false);
|
||||
}
|
||||
catch (ProcessCanceledException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
private void checkRebuild(@NotNull final ID<?, ?> indexId, final boolean cleanupOnly) {
|
||||
final AtomicInteger status = ourRebuildStatus.get(indexId);
|
||||
if (status.get() == OK) {
|
||||
return;
|
||||
}
|
||||
if (status.compareAndSet(REQUIRES_REBUILD, REBUILD_IN_PROGRESS)) {
|
||||
cleanupProcessedFlag();
|
||||
|
||||
advanceIndexVersion(indexId);
|
||||
|
||||
final Runnable rebuildRunnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
doClearIndex(indexId);
|
||||
if (!cleanupOnly) {
|
||||
scheduleIndexRebuild("checkRebuild");
|
||||
}
|
||||
}
|
||||
catch (StorageException e) {
|
||||
requestRebuild(indexId);
|
||||
LOG.info(e);
|
||||
}
|
||||
finally {
|
||||
status.compareAndSet(REBUILD_IN_PROGRESS, OK);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
if (cleanupOnly || myIsUnitTestMode) {
|
||||
rebuildRunnable.run();
|
||||
}
|
||||
else {
|
||||
//noinspection SSBasedInspection
|
||||
ApplicationManager.getApplication().invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
new Task.Modal(null, "Updating index", false) {
|
||||
@Override
|
||||
public void run(@NotNull final ProgressIndicator indicator) {
|
||||
indicator.setIndeterminate(true);
|
||||
rebuildRunnable.run();
|
||||
}
|
||||
}.queue();
|
||||
}
|
||||
}, ModalityState.NON_MODAL);
|
||||
}
|
||||
}
|
||||
|
||||
if (status.get() == REBUILD_IN_PROGRESS) {
|
||||
throw new ProcessCanceledException();
|
||||
}
|
||||
}
|
||||
|
||||
private static void scheduleIndexRebuild(String reason) {
|
||||
@@ -1547,9 +1491,11 @@ public class FileBasedIndexImpl extends FileBasedIndex {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void requestRebuild(ID<?, ?> indexId, Throwable throwable) {
|
||||
public void requestRebuild(final ID<?, ?> indexId, final Throwable throwable) {
|
||||
cleanupProcessedFlag();
|
||||
boolean requiresRebuildWasSet = ourRebuildStatus.get(indexId).compareAndSet(OK, REQUIRES_REBUILD);
|
||||
final AtomicInteger status = ourRebuildStatus.get(indexId);
|
||||
boolean requiresRebuildWasSet = status.compareAndSet(OK, REQUIRES_REBUILD);
|
||||
|
||||
if (requiresRebuildWasSet) {
|
||||
String message = "Rebuild requested for index " + indexId;
|
||||
Application app = ApplicationManager.getApplication();
|
||||
@@ -1560,6 +1506,47 @@ public class FileBasedIndexImpl extends FileBasedIndex {
|
||||
} else {
|
||||
LOG.info(message, throwable);
|
||||
}
|
||||
|
||||
cleanupProcessedFlag();
|
||||
|
||||
advanceIndexVersion(indexId);
|
||||
|
||||
final Runnable rebuildRunnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
doClearIndex(indexId);
|
||||
scheduleIndexRebuild("checkRebuild");
|
||||
}
|
||||
catch (StorageException e) {
|
||||
requestRebuild(indexId);
|
||||
LOG.info(e);
|
||||
}
|
||||
finally {
|
||||
status.compareAndSet(REQUIRES_REBUILD, OK);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
if (myIsUnitTestMode) {
|
||||
rebuildRunnable.run();
|
||||
}
|
||||
else {
|
||||
// we do invoke later since we can have read lock acquired
|
||||
//noinspection SSBasedInspection
|
||||
ApplicationManager.getApplication().invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
new Task.Modal(null, "Updating index", false) {
|
||||
@Override
|
||||
public void run(@NotNull final ProgressIndicator indicator) {
|
||||
indicator.setIndeterminate(true);
|
||||
rebuildRunnable.run();
|
||||
}
|
||||
}.queue();
|
||||
}
|
||||
}, ModalityState.NON_MODAL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user