-
-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2363 from Haehnchen/feature/model-wall-time
optimize class namespace loading cache Doctrine models, to reduce wall time calling
- Loading branch information
Showing
4 changed files
with
108 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,18 +2,12 @@ | |
|
||
import com.intellij.codeInsight.completion.PrefixMatcher; | ||
import com.intellij.openapi.project.Project; | ||
import com.intellij.util.Processor; | ||
import com.jetbrains.php.PhpIndex; | ||
import com.jetbrains.php.lang.psi.elements.PhpClass; | ||
import com.jetbrains.php.util.PhpContractUtil; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
import java.util.*; | ||
|
||
/** | ||
* @author Daniel Espendiller <[email protected]> | ||
|
@@ -29,7 +23,19 @@ public class PhpIndexUtil { | |
*/ | ||
@NotNull | ||
public static Collection<PhpClass> getPhpClassInsideNamespace(@NotNull Project project, @NotNull String namespaceName) { | ||
return getPhpClassInsideNamespace(PhpIndex.getInstance(project), namespaceName, 10); | ||
return getPhpClassInsideNamespace(PhpIndex.getInstance(project), namespaceName, false); | ||
} | ||
|
||
/** | ||
* Collect PhpClass which are inside current namespace and in sub-namespaces | ||
* | ||
* @param project current project | ||
* @param namespaceName namespace name should start with \ and end with "\" | ||
* @return classes inside namespace and sub-namespace | ||
*/ | ||
@NotNull | ||
public static Collection<PhpClass> getPhpClassInsideNamespace(@NotNull Project project, @NotNull String namespaceName, boolean excludeInterfaces) { | ||
return getPhpClassInsideNamespace(PhpIndex.getInstance(project), namespaceName, excludeInterfaces); | ||
} | ||
|
||
public static Collection<PhpClass> getAllSubclasses(@NotNull Project project, @NotNull String clazz) { | ||
|
@@ -45,20 +51,16 @@ public static Collection<PhpClass> getAllSubclasses(@NotNull Project project, @N | |
|
||
|
||
@NotNull | ||
private static Collection<PhpClass> getPhpClassInsideNamespace(@NotNull PhpIndex phpIndex, @NotNull String namespaceName, int maxDeep) { | ||
private static Collection<PhpClass> getPhpClassInsideNamespace(@NotNull PhpIndex phpIndex, @NotNull String namespaceName, boolean excludeInterfaces) { | ||
PhpContractUtil.assertFqn(namespaceName); | ||
|
||
Collection<String> classes = new HashSet<>() {{ | ||
addAll(phpIndex.getAllClassFqns(PrefixMatcher.ALWAYS_TRUE)); | ||
addAll(phpIndex.getAllInterfacesFqns(PrefixMatcher.ALWAYS_TRUE)); | ||
}}; | ||
|
||
Set<String> stringStream = classes.stream() | ||
.filter(s -> s.toLowerCase().startsWith(StringUtils.stripEnd(namespaceName.toLowerCase(), "\\") + "\\")) | ||
.collect(Collectors.toSet()); | ||
Collection<String> classes = new HashSet<>(phpIndex.getAllClassFqns(new MyPrefixMatcher(namespaceName))); | ||
if (!excludeInterfaces) { | ||
classes.addAll(phpIndex.getAllInterfacesFqns(new MyPrefixMatcher(namespaceName))); | ||
} | ||
|
||
Collection<PhpClass> clazzes = new HashSet<>(); | ||
for (String s : stringStream) { | ||
for (String s : classes) { | ||
clazzes.addAll(phpIndex.getAnyByFQN(s)); | ||
} | ||
|
||
|
@@ -73,4 +75,23 @@ public static boolean hasNamespace(@NotNull Project project, @NotNull String nam | |
|
||
return !PhpIndex.getInstance(project).getChildNamespacesByParentName(namespaceName + "\\").isEmpty(); | ||
} | ||
|
||
private static class MyPrefixMatcher extends PrefixMatcher { | ||
private final String namespaceName; | ||
|
||
public MyPrefixMatcher(@NotNull String namespaceName) { | ||
super(namespaceName); | ||
this.namespaceName = namespaceName; | ||
} | ||
|
||
@Override | ||
public boolean prefixMatches(@NotNull String name) { | ||
return name.startsWith(namespaceName); | ||
} | ||
|
||
@Override | ||
public @NotNull PrefixMatcher cloneWithPrefix(@NotNull String prefix) { | ||
return new MyPrefixMatcher(prefix); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters