per file read action during scanning file to index (EA-100454)

(cherry picked from commit 47907b4)
This commit is contained in:
Maxim.Mossienko
2017-05-02 16:30:52 +02:00
committed by Maxim.Mossienko
parent 1a30c27b66
commit ab18dd4a89
2 changed files with 55 additions and 58 deletions
@@ -2025,70 +2025,72 @@ public class FileBasedIndexImpl extends FileBasedIndex implements BaseComponent,
@Override
public boolean processFile(@NotNull final VirtualFile file) {
if (!file.isValid()) {
return true;
}
if (file instanceof VirtualFileSystemEntry && ((VirtualFileSystemEntry)file).isFileIndexed()) {
return true;
}
try (AccessToken ignore = ReadAction.start()) {
if (!file.isValid()) {
return true;
}
if (file instanceof VirtualFileSystemEntry && ((VirtualFileSystemEntry)file).isFileIndexed()) {
return true;
}
if (!(file instanceof VirtualFileWithId)) {
return true;
}
myFileTypeManager.freezeFileTypeTemporarilyIn(file, () -> {
boolean oldStuff = true;
if (file.isDirectory() || !isTooLarge(file)) {
final List<ID<?, ?>> affectedIndexCandidates = getAffectedIndexCandidates(file);
//noinspection ForLoopReplaceableByForEach
for (int i = 0, size = affectedIndexCandidates.size(); i < size; ++i) {
final ID<?, ?> indexId = affectedIndexCandidates.get(i);
try {
if (needsFileContentLoading(indexId) && shouldIndexFile(file, indexId)) {
if (myDoTraceForFilesToBeIndexed) {
LOG.info("Scheduling indexing of " + file + " by request of index " + indexId);
if (!(file instanceof VirtualFileWithId)) {
return true;
}
myFileTypeManager.freezeFileTypeTemporarilyIn(file, () -> {
boolean oldStuff = true;
if (file.isDirectory() || !isTooLarge(file)) {
final List<ID<?, ?>> affectedIndexCandidates = getAffectedIndexCandidates(file);
//noinspection ForLoopReplaceableByForEach
for (int i = 0, size = affectedIndexCandidates.size(); i < size; ++i) {
final ID<?, ?> indexId = affectedIndexCandidates.get(i);
try {
if (needsFileContentLoading(indexId) && shouldIndexFile(file, indexId)) {
if (myDoTraceForFilesToBeIndexed) {
LOG.info("Scheduling indexing of " + file + " by request of index " + indexId);
}
synchronized (myFiles) {
myFiles.add(file);
}
oldStuff = false;
break;
}
synchronized (myFiles) {
myFiles.add(file);
}
catch (RuntimeException e) {
final Throwable cause = e.getCause();
if (cause instanceof IOException || cause instanceof StorageException) {
LOG.info(e);
requestRebuild(indexId);
}
else {
throw e;
}
oldStuff = false;
break;
}
}
catch (RuntimeException e) {
final Throwable cause = e.getCause();
if (cause instanceof IOException || cause instanceof StorageException) {
LOG.info(e);
requestRebuild(indexId);
}
else {
throw e;
}
}
}
}
FileContent fileContent = null;
int inputId = Math.abs(getIdMaskingNonIdBasedFile(file));
for (ID<?, ?> indexId : myNotRequiringContentIndices) {
if (shouldIndexFile(file, indexId)) {
oldStuff = false;
if (fileContent == null) {
fileContent = new FileContentImpl(file);
FileContent fileContent = null;
int inputId = Math.abs(getIdMaskingNonIdBasedFile(file));
for (ID<?, ?> indexId : myNotRequiringContentIndices) {
if (shouldIndexFile(file, indexId)) {
oldStuff = false;
if (fileContent == null) {
fileContent = new FileContentImpl(file);
}
updateSingleIndex(indexId, file, inputId, fileContent);
}
updateSingleIndex(indexId, file, inputId, fileContent);
}
}
IndexingStamp.flushCache(inputId);
IndexingStamp.flushCache(inputId);
if (oldStuff && file instanceof VirtualFileSystemEntry) {
((VirtualFileSystemEntry)file).setFileIndexed(true);
}
});
if (oldStuff && file instanceof VirtualFileSystemEntry) {
((VirtualFileSystemEntry)file).setFileIndexed(true);
}
});
if (myProgressIndicator != null && file.isDirectory()) { // once for dir is cheap enough
myProgressIndicator.checkCanceled();
myProgressIndicator.setText("Scanning files to index");
if (myProgressIndicator != null && file.isDirectory()) { // once for dir is cheap enough
myProgressIndicator.checkCanceled();
myProgressIndicator.setText("Scanning files to index");
}
return true;
}
return true;
}
}
@@ -16,7 +16,6 @@
package com.intellij.util.indexing;
import com.intellij.openapi.application.AccessToken;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ReadAction;
import com.intellij.openapi.extensions.Extensions;
import com.intellij.openapi.fileTypes.FileTypeManager;
@@ -126,10 +125,6 @@ public class FileBasedIndexScanRunnableCollectorImpl extends FileBasedIndexScanR
}
}
for(int i = 0, size = tasks.size(); i < size; ++i) {
Runnable runnable = tasks.get(i);
tasks.set(i, () -> ApplicationManager.getApplication().runReadAction(runnable));
}
return tasks;
}
}