mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
performance: directly process VFileEvents
This commit is contained in:
@@ -18,12 +18,13 @@ package com.intellij.util.indexing;
|
||||
import com.intellij.openapi.application.PathManager;
|
||||
import com.intellij.openapi.roots.ContentIterator;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.vfs.*;
|
||||
import com.intellij.openapi.vfs.impl.BulkVirtualFileListenerAdapter;
|
||||
import com.intellij.openapi.vfs.VfsUtilCore;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.openapi.vfs.VirtualFileVisitor;
|
||||
import com.intellij.openapi.vfs.newvfs.BulkFileListener;
|
||||
import com.intellij.openapi.vfs.newvfs.ManagingFS;
|
||||
import com.intellij.openapi.vfs.newvfs.NewVirtualFile;
|
||||
import com.intellij.openapi.vfs.newvfs.events.VFileEvent;
|
||||
import com.intellij.openapi.vfs.newvfs.events.*;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -31,7 +32,7 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class IndexedFilesListener implements BulkFileListener, VirtualFileListener {
|
||||
public abstract class IndexedFilesListener implements BulkFileListener {
|
||||
private final ManagingFS myManagingFS = ManagingFS.getInstance();
|
||||
@Nullable private final String myConfigPath;
|
||||
@Nullable private final String myLogPath;
|
||||
@@ -41,61 +42,6 @@ public abstract class IndexedFilesListener implements BulkFileListener, VirtualF
|
||||
myLogPath = calcConfigPath(PathManager.getLogPath());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fileMoved(@NotNull VirtualFileMoveEvent event) {
|
||||
buildIndicesForFileRecursively(event.getFile(), false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fileCreated(@NotNull final VirtualFileEvent event) {
|
||||
buildIndicesForFileRecursively(event.getFile(), false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fileCopied(@NotNull final VirtualFileCopyEvent event) {
|
||||
buildIndicesForFileRecursively(event.getFile(), false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeFileDeletion(@NotNull final VirtualFileEvent event) {
|
||||
invalidateIndicesRecursively(event.getFile(), false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeContentsChange(@NotNull final VirtualFileEvent event) {
|
||||
invalidateIndicesRecursively(event.getFile(), true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void contentsChanged(@NotNull final VirtualFileEvent event) {
|
||||
buildIndicesForFileRecursively(event.getFile(), true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforePropertyChange(@NotNull final VirtualFilePropertyEvent event) {
|
||||
String propertyName = event.getPropertyName();
|
||||
|
||||
if (propertyName.equals(VirtualFile.PROP_NAME)) {
|
||||
// indexes may depend on file name
|
||||
// name change may lead to filetype change so the file might become not indexable
|
||||
// in general case have to 'unindex' the file and index it again if needed after the name has been changed
|
||||
invalidateIndicesRecursively(event.getFile(), false);
|
||||
} else if (propertyName.equals(VirtualFile.PROP_ENCODING)) {
|
||||
invalidateIndicesRecursively(event.getFile(), true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void propertyChanged(@NotNull final VirtualFilePropertyEvent event) {
|
||||
String propertyName = event.getPropertyName();
|
||||
if (propertyName.equals(VirtualFile.PROP_NAME)) {
|
||||
// indexes may depend on file name
|
||||
buildIndicesForFileRecursively(event.getFile(), false);
|
||||
} else if (propertyName.equals(VirtualFile.PROP_ENCODING)) {
|
||||
buildIndicesForFileRecursively(event.getFile(), true);
|
||||
}
|
||||
}
|
||||
|
||||
protected void buildIndicesForFileRecursively(@NotNull final VirtualFile file, final boolean contentChange) {
|
||||
if (file.isDirectory()) {
|
||||
final ContentIterator iterator = fileOrDir -> {
|
||||
@@ -147,14 +93,59 @@ public abstract class IndexedFilesListener implements BulkFileListener, VirtualF
|
||||
@Override
|
||||
public void before(@NotNull List<? extends VFileEvent> events) {
|
||||
for (VFileEvent event : events) {
|
||||
BulkVirtualFileListenerAdapter.fireBefore(this, event);
|
||||
if (event instanceof VFileContentChangeEvent) {
|
||||
invalidateIndicesRecursively(((VFileContentChangeEvent)event).getFile(), true);
|
||||
}
|
||||
else if (event instanceof VFileDeleteEvent) {
|
||||
invalidateIndicesRecursively(((VFileDeleteEvent)event).getFile(), false);
|
||||
}
|
||||
else if (event instanceof VFilePropertyChangeEvent) {
|
||||
final VFilePropertyChangeEvent pce = (VFilePropertyChangeEvent)event;
|
||||
String propertyName = pce.getPropertyName();
|
||||
if (propertyName.equals(VirtualFile.PROP_NAME)) {
|
||||
// indexes may depend on file name
|
||||
// name change may lead to filetype change so the file might become not indexable
|
||||
// in general case have to 'unindex' the file and index it again if needed after the name has been changed
|
||||
invalidateIndicesRecursively(pce.getFile(), false);
|
||||
} else if (propertyName.equals(VirtualFile.PROP_ENCODING)) {
|
||||
invalidateIndicesRecursively(pce.getFile(), true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void after(@NotNull List<? extends VFileEvent> events) {
|
||||
for (VFileEvent event : events) {
|
||||
BulkVirtualFileListenerAdapter.fireAfter(this, event);
|
||||
if (event instanceof VFileContentChangeEvent) {
|
||||
buildIndicesForFileRecursively(((VFileContentChangeEvent)event).getFile(), true);
|
||||
}
|
||||
else if (event instanceof VFileCopyEvent) {
|
||||
final VFileCopyEvent ce = (VFileCopyEvent)event;
|
||||
final VirtualFile copy = ce.getNewParent().findChild(ce.getNewChildName());
|
||||
if (copy != null) {
|
||||
buildIndicesForFileRecursively(copy, false);
|
||||
}
|
||||
}
|
||||
else if (event instanceof VFileCreateEvent) {
|
||||
final VirtualFile newChild = event.getFile();
|
||||
if (newChild != null) {
|
||||
buildIndicesForFileRecursively(newChild, false);
|
||||
}
|
||||
}
|
||||
else if (event instanceof VFileMoveEvent) {
|
||||
buildIndicesForFileRecursively(((VFileMoveEvent)event).getFile(), false);
|
||||
}
|
||||
else if (event instanceof VFilePropertyChangeEvent) {
|
||||
final VFilePropertyChangeEvent pce = (VFilePropertyChangeEvent)event;
|
||||
String propertyName = pce.getPropertyName();
|
||||
if (propertyName.equals(VirtualFile.PROP_NAME)) {
|
||||
// indexes may depend on file name
|
||||
buildIndicesForFileRecursively(pce.getFile(), false);
|
||||
} else if (propertyName.equals(VirtualFile.PROP_ENCODING)) {
|
||||
buildIndicesForFileRecursively(pce.getFile(), true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user