indexes: flush cache before return if file is marked as indexed since we still load its state

GitOrigin-RevId: ef455cf865f488b098a2ec7cdcf08255f00fde47
This commit is contained in:
Dmitry Batkovich
2020-10-20 13:53:03 +00:00
committed by intellij-monorepo-bot
parent 63ab83fd5f
commit 2a6be7f346
2 changed files with 19 additions and 1 deletions
@@ -509,6 +509,22 @@ public final class IndexingStamp {
public static void flushCache(@Nullable Integer finishedFile) {
if (finishedFile != null && finishedFile == INVALID_FILE_ID) finishedFile = 0;
if (finishedFile != null) {
Lock readLock = getStripedLock(finishedFile).readLock();
readLock.lock();
try {
Timestamps timestamps = ourTimestampsCache.get(finishedFile);
if (timestamps == null) return;
if (!timestamps.isDirty()) {
ourTimestampsCache.remove(finishedFile);
return;
}
} finally {
readLock.unlock();
}
}
// todo make better (e.g. FinishedFiles striping, remove integers)
while (finishedFile == null || !ourFinishedFiles.offer(finishedFile)) {
List<Integer> files = new ArrayList<>(ourFinishedFiles.size());
@@ -60,8 +60,9 @@ final class UnindexedFilesFinder implements VirtualFileFilter {
IndexedFileImpl indexedFile = new IndexedFileImpl(file, myProject);
if (file instanceof VirtualFileSystemEntry && ((VirtualFileSystemEntry)file).isFileIndexed()) {
int inputId = Math.abs(FileBasedIndexImpl.getIdMaskingNonIdBasedFile(file));
if (myRunExtensionsForFilesMarkedAsIndexed && myShouldProcessUpToDateFiles) {
int inputId = Math.abs(FileBasedIndexImpl.getIdMaskingNonIdBasedFile(file));
List<ID<?, ?>> ids = IndexingStamp.getNontrivialFileIndexedStates(inputId);
for (FileBasedIndexInfrastructureExtension.FileIndexingStatusProcessor processor : myStateProcessors) {
for (ID<?, ?> id : ids) {
@@ -74,6 +75,7 @@ final class UnindexedFilesFinder implements VirtualFileFilter {
}
}
if (!shouldIndexFile.get()) {
IndexingStamp.flushCache(inputId);
return false;
}
}