mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
indexes: do not send to up-date all the files on the first indexation
GitOrigin-RevId: 092efe8ace44e22e6a23d29e2eb5aac68d5b7eb1
This commit is contained in:
committed by
intellij-monorepo-bot
parent
fc66732843
commit
8f0bdd4e89
@@ -3,16 +3,17 @@ package com.intellij.psi.search;
|
||||
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.fileTypes.FileType;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.indexing.*;
|
||||
import com.intellij.util.indexing.FileBasedIndexExtension;
|
||||
import com.intellij.util.indexing.FileIndexingState;
|
||||
import com.intellij.util.indexing.IndexedFile;
|
||||
import com.intellij.util.indexing.VfsAwareMapReduceIndex;
|
||||
import com.intellij.util.indexing.impl.IndexStorage;
|
||||
import com.intellij.util.indexing.impl.MapInputDataDiffBuilder;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
class FileTypeMapReduceIndex extends VfsAwareMapReduceIndex<FileType, Void> {
|
||||
private static final Logger LOG = Logger.getInstance(FileTypeIndexImpl.class);
|
||||
@@ -22,16 +23,18 @@ class FileTypeMapReduceIndex extends VfsAwareMapReduceIndex<FileType, Void> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isIndexedStateForFile(int fileId, @NotNull IndexedFile file) {
|
||||
boolean isIndexed = super.isIndexedStateForFile(fileId, file);
|
||||
if (!isIndexed) return false;
|
||||
public @NotNull FileIndexingState getIndexingStateForFile(int fileId, @NotNull IndexedFile file) {
|
||||
@NotNull FileIndexingState isIndexed = super.getIndexingStateForFile(fileId, file);
|
||||
if (isIndexed != FileIndexingState.UP_TO_DATE) return isIndexed;
|
||||
try {
|
||||
Collection<FileType> inputData = ((MapInputDataDiffBuilder<FileType, Void>) getKeysDiffBuilder(fileId)).getKeys();
|
||||
FileType indexedFileType = ContainerUtil.getFirstItem(inputData);
|
||||
return FileTypeKeyDescriptor.INSTANCE.isEqual(indexedFileType, file.getFileType());
|
||||
return FileTypeKeyDescriptor.INSTANCE.isEqual(indexedFileType, file.getFileType())
|
||||
? FileIndexingState.UP_TO_DATE
|
||||
: FileIndexingState.OUT_DATED;
|
||||
} catch (IOException e) {
|
||||
LOG.error(e);
|
||||
return false;
|
||||
return FileIndexingState.OUT_DATED;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,8 +6,6 @@ import com.intellij.psi.search.GlobalSearchScope
|
||||
import com.intellij.util.Processor
|
||||
import com.intellij.util.indexing.impl.AbstractUpdateData
|
||||
import com.intellij.util.indexing.snapshot.EmptyValueContainer
|
||||
import java.lang.UnsupportedOperationException
|
||||
import java.util.concurrent.locks.Lock
|
||||
import java.util.concurrent.locks.ReadWriteLock
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock
|
||||
|
||||
@@ -28,7 +26,7 @@ class EmptyUpdatableIndex<Key, Value, Input> : UpdatableIndex<Key, Value, Input>
|
||||
|
||||
override fun setIndexedStateForFile(fileId: Int, file: IndexedFile) = Unit
|
||||
override fun resetIndexedStateForFile(fileId: Int) {}
|
||||
override fun isIndexedStateForFile(fileId: Int, file: IndexedFile): Boolean = false
|
||||
override fun getIndexingStateForFile(fileId: Int, file: IndexedFile): FileIndexingState = FileIndexingState.NOT_INDEXED
|
||||
|
||||
override fun getModificationStamp(): Long = 0
|
||||
|
||||
|
||||
@@ -1199,7 +1199,7 @@ public final class FileBasedIndexImpl extends FileBasedIndexEx {
|
||||
try {
|
||||
ProgressManager.checkCanceled();
|
||||
final ID<?, ?> indexId = affectedIndexCandidates.get(i);
|
||||
if (shouldIndexFile(fc, indexId) == FileIndexingState.SHOULD_INDEX) {
|
||||
if (getInputFilter(indexId).acceptInput(file) && getIndexingState(fc, indexId).updateRequired()) {
|
||||
ProgressManager.checkCanceled();
|
||||
if (!updateSingleIndex(indexId, file, inputId, fc)) {
|
||||
setIndexedStatus.set(Boolean.FALSE);
|
||||
@@ -1219,7 +1219,7 @@ public final class FileBasedIndexImpl extends FileBasedIndexEx {
|
||||
|
||||
for(ID<?, ?> indexId : currentIndexedStates) {
|
||||
ProgressManager.checkCanceled();
|
||||
if (!getIndex(indexId).isIndexedStateForFile(inputId, fc)) {
|
||||
if (getIndex(indexId).getIndexingStateForFile(inputId, fc).updateRequired()) {
|
||||
ProgressManager.checkCanceled();
|
||||
if (!updateSingleIndex(indexId, file, inputId, null)) {
|
||||
setIndexedStatus.set(Boolean.FALSE);
|
||||
@@ -1535,13 +1535,19 @@ public final class FileBasedIndexImpl extends FileBasedIndexEx {
|
||||
}
|
||||
|
||||
FileIndexingState shouldIndexFile(@NotNull IndexedFile file, @NotNull ID<?, ?> indexId) {
|
||||
VirtualFile virtualFile = file.getFile();
|
||||
if (!getInputFilter(indexId).acceptInput(virtualFile)) {
|
||||
return FileIndexingState.SHOULD_NOT_INDEX;
|
||||
if (!getInputFilter(indexId).acceptInput(file.getFile())) {
|
||||
return getIndexingState(file, indexId) == FileIndexingState.NOT_INDEXED
|
||||
? FileIndexingState.UP_TO_DATE
|
||||
: FileIndexingState.OUT_DATED;
|
||||
}
|
||||
return (isMock(virtualFile) || !getIndex(indexId).isIndexedStateForFile(((NewVirtualFile) virtualFile).getId(), file))
|
||||
? FileIndexingState.SHOULD_INDEX
|
||||
: FileIndexingState.UP_TO_DATE;
|
||||
return getIndexingState(file, indexId);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private FileIndexingState getIndexingState(@NotNull IndexedFile file, @NotNull ID<?, ?> indexId) {
|
||||
VirtualFile virtualFile = file.getFile();
|
||||
if (isMock(virtualFile)) return FileIndexingState.NOT_INDEXED;
|
||||
return getIndex(indexId).getIndexingStateForFile(((NewVirtualFile)virtualFile).getId(), file);
|
||||
}
|
||||
|
||||
static boolean isMock(final VirtualFile file) {
|
||||
@@ -1743,9 +1749,4 @@ public final class FileBasedIndexImpl extends FileBasedIndexEx {
|
||||
}
|
||||
return version;
|
||||
}
|
||||
|
||||
@ApiStatus.Internal
|
||||
enum FileIndexingState {
|
||||
SHOULD_INDEX, SHOULD_NOT_INDEX, UP_TO_DATE
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.util.indexing;
|
||||
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
@ApiStatus.Experimental
|
||||
public enum FileIndexingState {
|
||||
NOT_INDEXED,
|
||||
OUT_DATED,
|
||||
UP_TO_DATE;
|
||||
|
||||
public boolean updateRequired() {
|
||||
return this != UP_TO_DATE;
|
||||
}
|
||||
}
|
||||
@@ -195,9 +195,11 @@ public class IndexingStamp {
|
||||
return version;
|
||||
}
|
||||
|
||||
public static boolean isFileIndexedStateCurrent(int fileId, ID<?, ?> indexName) {
|
||||
public static FileIndexingState isFileIndexedStateCurrent(int fileId, ID<?, ?> indexName) {
|
||||
try {
|
||||
return getIndexStamp(fileId, indexName) == getIndexCreationStamp(indexName);
|
||||
long stamp = getIndexStamp(fileId, indexName);
|
||||
if (stamp == 0) return FileIndexingState.NOT_INDEXED;
|
||||
return stamp == getIndexCreationStamp(indexName) ? FileIndexingState.UP_TO_DATE : FileIndexingState.OUT_DATED;
|
||||
}
|
||||
catch (RuntimeException e) {
|
||||
final Throwable cause = e.getCause();
|
||||
@@ -206,7 +208,7 @@ public class IndexingStamp {
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
return FileIndexingState.OUT_DATED;
|
||||
}
|
||||
|
||||
public static void setFileIndexedStateCurrent(int fileId, ID<?, ?> id) {
|
||||
|
||||
@@ -59,8 +59,7 @@ class UnindexedFilesFinder implements VirtualFileFilter {
|
||||
boolean isDirectory = file.isDirectory();
|
||||
int inputId = Math.abs(FileBasedIndexImpl.getIdMaskingNonIdBasedFile(file));
|
||||
if (!isDirectory && !myFileBasedIndex.isTooLarge(file)) {
|
||||
|
||||
if (!myFileTypeIndex.isIndexedStateForFile(inputId, fileContent)) {
|
||||
if (myFileTypeIndex.getIndexingStateForFile(inputId, fileContent) == FileIndexingState.OUT_DATED) {
|
||||
myFileBasedIndex.dropNontrivialIndexedStates(inputId);
|
||||
shouldIndexFile.set(true);
|
||||
} else {
|
||||
@@ -70,10 +69,10 @@ class UnindexedFilesFinder implements VirtualFileFilter {
|
||||
final ID<?, ?> indexId = affectedIndexCandidates.get(i);
|
||||
try {
|
||||
if (myFileBasedIndex.needsFileContentLoading(indexId)) {
|
||||
FileBasedIndexImpl.FileIndexingState fileIndexingState = myFileBasedIndex.shouldIndexFile(fileContent, indexId);
|
||||
if (fileIndexingState == FileBasedIndexImpl.FileIndexingState.UP_TO_DATE) {
|
||||
FileIndexingState fileIndexingState = myFileBasedIndex.shouldIndexFile(fileContent, indexId);
|
||||
if (fileIndexingState == FileIndexingState.UP_TO_DATE) {
|
||||
myStateProcessors.forEach(p -> p.processUpToDateFile(file, inputId, indexId));
|
||||
} else if (fileIndexingState == FileBasedIndexImpl.FileIndexingState.SHOULD_INDEX) {
|
||||
} else if (fileIndexingState.updateRequired()) {
|
||||
if (myDoTraceForFilesToBeIndexed) {
|
||||
LOG.trace("Scheduling indexing of " + file + " by request of index " + indexId);
|
||||
}
|
||||
@@ -97,7 +96,7 @@ class UnindexedFilesFinder implements VirtualFileFilter {
|
||||
}
|
||||
|
||||
for (ID<?, ?> indexId : myFileBasedIndex.getContentLessIndexes(isDirectory)) {
|
||||
if (myFileBasedIndex.shouldIndexFile(fileContent, indexId) == FileBasedIndexImpl.FileIndexingState.SHOULD_INDEX) {
|
||||
if (myFileBasedIndex.shouldIndexFile(fileContent, indexId).updateRequired()) {
|
||||
myFileBasedIndex.updateSingleIndex(indexId, file, inputId, new IndexedFileWrapper(fileContent));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,7 +54,8 @@ public interface UpdatableIndex<Key, Value, Input> extends InvertedIndex<Key,Val
|
||||
void setIndexedStateForFile(int fileId, @NotNull IndexedFile file);
|
||||
void resetIndexedStateForFile(int fileId);
|
||||
|
||||
boolean isIndexedStateForFile(int fileId, @NotNull IndexedFile file);
|
||||
@NotNull
|
||||
FileIndexingState getIndexingStateForFile(int fileId, @NotNull IndexedFile file);
|
||||
|
||||
long getModificationStamp();
|
||||
|
||||
|
||||
@@ -209,22 +209,23 @@ public class VfsAwareMapReduceIndex<Key, Value> extends MapReduceIndex<Key, Valu
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isIndexedStateForFile(int fileId, @NotNull IndexedFile file) {
|
||||
if (!IndexingStamp.isFileIndexedStateCurrent(fileId, (ID<?, ?>)myIndexId)) {
|
||||
return false;
|
||||
public @NotNull FileIndexingState getIndexingStateForFile(int fileId, @NotNull IndexedFile file) {
|
||||
FileIndexingState baseState = IndexingStamp.isFileIndexedStateCurrent(fileId, (ID<?, ?>)myIndexId);
|
||||
if (baseState != FileIndexingState.UP_TO_DATE) {
|
||||
return baseState;
|
||||
}
|
||||
if (mySubIndexerRetriever == null) return true;
|
||||
if (mySubIndexerRetriever == null) return FileIndexingState.UP_TO_DATE;
|
||||
if (!(file instanceof FileContent)) {
|
||||
if (((CompositeDataIndexer)myIndexer).requiresContentForSubIndexerEvaluation(file)) {
|
||||
return isIndexConfigurationUpToDate(fileId, file);
|
||||
return isIndexConfigurationUpToDate(fileId, file) ? FileIndexingState.UP_TO_DATE : FileIndexingState.OUT_DATED;
|
||||
}
|
||||
}
|
||||
try {
|
||||
return mySubIndexerRetriever.isIndexed(fileId, file);
|
||||
return mySubIndexerRetriever.isIndexed(fileId, file) ? FileIndexingState.UP_TO_DATE : FileIndexingState.OUT_DATED;
|
||||
}
|
||||
catch (IOException e) {
|
||||
LOG.error(e);
|
||||
return false;
|
||||
return FileIndexingState.OUT_DATED;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user