diff --git a/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndexDataInitialization.java b/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndexDataInitialization.java index ce0ec195dcef..544ed13bae42 100644 --- a/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndexDataInitialization.java +++ b/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndexDataInitialization.java @@ -153,12 +153,10 @@ class FileBasedIndexDataInitialization extends IndexDataInitializer myProjectsBeingUpdated = ContainerUtil.newConcurrentSet(); + private final IntSet myStaleIds = new IntOpenHashSet(); private final Lock myReadLock; public final Lock myWriteLock; @@ -310,6 +309,12 @@ public final class FileBasedIndexImpl extends FileBasedIndexEx { } } + void addStaleIds(@NotNull IntSet staleIds) { + synchronized (myStaleIds) { + myStaleIds.addAll(staleIds); + } + } + static class MyShutDownTask implements Runnable { @Override public void run() { @@ -748,11 +753,28 @@ public final class FileBasedIndexImpl extends FileBasedIndexEx { } void filesUpdateStarted(Project project) { + ensureStaleIdsDeleted(); getChangedFilesCollector().ensureUpToDate(); myProjectsBeingUpdated.add(project); incrementFilesModCount(); } + void ensureStaleIdsDeleted() { + waitUntilIndicesAreInitialized(); + synchronized (myStaleIds) { + if (myStaleIds.isEmpty()) return; + try { + StaleIndexesChecker.clearStaleIndexes(myStaleIds); + } + catch (Exception e) { + LOG.error(e); + } + finally { + myStaleIds.clear(); + } + } + } + void filesUpdateFinished(@NotNull Project project) { myProjectsBeingUpdated.remove(project); incrementFilesModCount(); diff --git a/platform/lang-impl/src/com/intellij/util/indexing/RegisteredIndexes.java b/platform/lang-impl/src/com/intellij/util/indexing/RegisteredIndexes.java index c283be3dd21e..d07675e52fdd 100644 --- a/platform/lang-impl/src/com/intellij/util/indexing/RegisteredIndexes.java +++ b/platform/lang-impl/src/com/intellij/util/indexing/RegisteredIndexes.java @@ -104,6 +104,7 @@ public final class RegisteredIndexes { void ensureLoadedIndexesUpToDate() { myAllIndicesInitializedFuture = IndexDataInitializer.submitGenesisTask(() -> { if (!myShutdownPerformed.get()) { + myFileBasedIndex.ensureStaleIdsDeleted(); myFileBasedIndex.getChangedFilesCollector().ensureUpToDateAsync(); } return null;