From 7f8c469425559927479a96121a49be8a9e96e10b Mon Sep 17 00:00:00 2001 From: Eugene Zhuravlev Date: Mon, 9 Nov 2009 14:20:53 +0300 Subject: [PATCH] on shutdown do not re-index dirty files, just remove relevant data from indices. --- .../com/intellij/util/indexing/FileBasedIndex.java | 77 +++++++++++++--------- 1 file changed, 46 insertions(+), 31 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndex.java b/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndex.java index fb18b51a6e..c0b7224835 100644 --- a/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndex.java +++ b/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndex.java @@ -449,7 +449,7 @@ public class FileBasedIndex implements ApplicationComponent { LOG.info("START INDEX SHUTDOWN"); try { - myChangedFilesCollector.forceUpdate(null, null); + myChangedFilesCollector.forceUpdate(null, null, true); for (ID indexId : myIndices.keySet()) { final UpdatableIndex index = getIndex(indexId); @@ -578,7 +578,7 @@ public class FileBasedIndex implements ApplicationComponent { if (isUpToDateCheckEnabled()) { try { checkRebuild(indexId, false); - myChangedFilesCollector.forceUpdate(project, filter); + myChangedFilesCollector.forceUpdate(project, filter, false); indexUnsavedDocuments(indexId, project, filter); } catch (StorageException e) { @@ -1184,7 +1184,7 @@ private boolean indexUnsavedDocument(final Document document, final ID req public void processRefreshedFile(@NotNull Project project, final com.intellij.ide.caches.FileContent fileContent) { myChangedFilesCollector.ensureAllInvalidateTasksCompleted(); - myChangedFilesCollector.processFileImpl(project, fileContent); + myChangedFilesCollector.processFileImpl(project, fileContent, false); } public void indexFileContent(@Nullable Project project, com.intellij.ide.caches.FileContent content) { @@ -1506,31 +1506,9 @@ private boolean indexUnsavedDocument(final Document document, final ID req else { final InvalidationTask invalidator = new InvalidationTask(file) { public void run() { - Throwable unexpectedError = null; - for (ID indexId : affectedIndices) { - try { - updateSingleIndex(indexId, file, null); - } - catch (StorageException e) { - LOG.info(e); - requestRebuild(indexId); - } - catch (ProcessCanceledException ignored) { - } - catch (Throwable e) { - LOG.info(e); - if (unexpectedError == null) { - unexpectedError = e; - } - } - } - IndexingStamp.flushCache(); - if (unexpectedError != null) { - LOG.error(unexpectedError); - } + removeFileDataFromIndices(affectedIndices, file); } }; - w.lock(); try { myFutureInvalidations.offer(invalidator); @@ -1544,6 +1522,31 @@ private boolean indexUnsavedDocument(final Document document, final ID req } } + private void removeFileDataFromIndices(List> affectedIndices, VirtualFile file) { + Throwable unexpectedError = null; + for (ID indexId : affectedIndices) { + try { + updateSingleIndex(indexId, file, null); + } + catch (StorageException e) { + LOG.info(e); + requestRebuild(indexId); + } + catch (ProcessCanceledException ignored) { + } + catch (Throwable e) { + LOG.info(e); + if (unexpectedError == null) { + unexpectedError = e; + } + } + } + IndexingStamp.flushCache(); + if (unexpectedError != null) { + LOG.error(unexpectedError); + } + } + public void ensureAllInvalidateTasksCompleted() { final int size; r.lock(); @@ -1615,14 +1618,14 @@ private boolean indexUnsavedDocument(final Document document, final ID req private final Semaphore myForceUpdateSemaphore = new Semaphore(); - public void forceUpdate(@Nullable Project project, @Nullable GlobalSearchScope filter) { + public void forceUpdate(@Nullable Project project, @Nullable GlobalSearchScope filter, boolean onlyRemoveOutdatedData) { myChangedFilesCollector.ensureAllInvalidateTasksCompleted(); for (VirtualFile file: getAllFilesToUpdate()) { if (filter == null || filter.accept(file)) { try { myForceUpdateSemaphore.down(); // process only files that can affect result - processFileImpl(project, new com.intellij.ide.caches.FileContent(file)); + processFileImpl(project, new com.intellij.ide.caches.FileContent(file), onlyRemoveOutdatedData); } finally { myForceUpdateSemaphore.up(); @@ -1642,7 +1645,7 @@ private boolean indexUnsavedDocument(final Document document, final ID req } } - private void processFileImpl(Project project, final com.intellij.ide.caches.FileContent fileContent) { + private void processFileImpl(Project project, final com.intellij.ide.caches.FileContent fileContent, boolean onlyRemoveOutdatedData) { final VirtualFile file = fileContent.getVirtualFile(); final boolean reallyRemoved; w.lock(); @@ -1653,7 +1656,19 @@ private boolean indexUnsavedDocument(final Document document, final ID req w.unlock(); } if (reallyRemoved && file.isValid()) { - indexFileContent(project, fileContent); + if (onlyRemoveOutdatedData) { + // on shutdown there is no need to re-index the file, just remove outdated data from indices + final List> affected = new ArrayList>(); + for (final ID indexId : myIndices.keySet()) { + if (getInputFilter(indexId).acceptInput(file)) { + affected.add(indexId); + } + } + removeFileDataFromIndices(affected, file); + } + else { + indexFileContent(project, fileContent); + } IndexingStamp.flushCache(); } } @@ -1775,7 +1790,7 @@ private boolean indexUnsavedDocument(final Document document, final ID req } public void removeIndexableSet(IndexableFileSet set) { - myChangedFilesCollector.forceUpdate(null, null); + myChangedFilesCollector.forceUpdate(null, null, true); myIndexableSets.remove(set); } -- 2.11.4.GIT