Fix performance issue (#18128)

* Fix ClassGraph

* Use CONST
This commit is contained in:
Mohit Yadav 2024-10-05 23:08:22 +05:30 committed by GitHub
parent e44c8d4f31
commit 7ae81272b3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 3 deletions

View File

@ -15,6 +15,7 @@ package org.openmetadata.service;
import static org.openmetadata.common.utils.CommonUtil.listOf; import static org.openmetadata.common.utils.CommonUtil.listOf;
import static org.openmetadata.common.utils.CommonUtil.listOrEmpty; import static org.openmetadata.common.utils.CommonUtil.listOrEmpty;
import static org.openmetadata.service.resources.CollectionRegistry.PACKAGES;
import static org.openmetadata.service.resources.tags.TagLabelUtil.addDerivedTags; import static org.openmetadata.service.resources.tags.TagLabelUtil.addDerivedTags;
import static org.openmetadata.service.util.EntityUtil.getFlattenedEntityField; import static org.openmetadata.service.util.EntityUtil.getFlattenedEntityField;
@ -560,7 +561,11 @@ public final class Entity {
/** Compile a list of REST collections based on Resource classes marked with {@code Repository} annotation */ /** Compile a list of REST collections based on Resource classes marked with {@code Repository} annotation */
private static List<Class<?>> getRepositories() { private static List<Class<?>> getRepositories() {
try (ScanResult scanResult = new ClassGraph().enableAnnotationInfo().scan()) { try (ScanResult scanResult =
new ClassGraph()
.enableAnnotationInfo()
.acceptPackages(PACKAGES.toArray(new String[0]))
.scan()) {
ClassInfoList classList = scanResult.getClassesWithAnnotation(Repository.class); ClassInfoList classList = scanResult.getClassesWithAnnotation(Repository.class);
return classList.loadClasses(); return classList.loadClasses();
} }

View File

@ -51,6 +51,7 @@ import org.openmetadata.service.util.ReflectionUtil;
*/ */
@Slf4j @Slf4j
public final class CollectionRegistry { public final class CollectionRegistry {
public static final List<String> PACKAGES = List.of("org.openmetadata", "io.collate");
private static CollectionRegistry instance = null; private static CollectionRegistry instance = null;
private static volatile boolean initialized = false; private static volatile boolean initialized = false;
@ -110,7 +111,8 @@ public final class CollectionRegistry {
* those conditions and makes it available for listing them over API to author expressions in Rules. * those conditions and makes it available for listing them over API to author expressions in Rules.
*/ */
private void loadConditionFunctions() { private void loadConditionFunctions() {
try (ScanResult scanResult = new ClassGraph().enableAllInfo().scan()) { try (ScanResult scanResult =
new ClassGraph().enableAllInfo().acceptPackages(PACKAGES.toArray(new String[0])).scan()) {
for (ClassInfo classInfo : scanResult.getClassesWithMethodAnnotation(Function.class)) { for (ClassInfo classInfo : scanResult.getClassesWithMethodAnnotation(Function.class)) {
List<Method> methods = List<Method> methods =
ReflectionUtil.getMethodsAnnotatedWith(classInfo.loadClass(), Function.class); ReflectionUtil.getMethodsAnnotatedWith(classInfo.loadClass(), Function.class);
@ -220,7 +222,11 @@ public final class CollectionRegistry {
/** Compile a list of REST collections based on Resource classes marked with {@code Collection} annotation */ /** Compile a list of REST collections based on Resource classes marked with {@code Collection} annotation */
private static List<CollectionDetails> getCollections() { private static List<CollectionDetails> getCollections() {
try (ScanResult scanResult = new ClassGraph().enableAnnotationInfo().scan()) { try (ScanResult scanResult =
new ClassGraph()
.enableAnnotationInfo()
.acceptPackages(PACKAGES.toArray(new String[0]))
.scan()) {
ClassInfoList classList = scanResult.getClassesWithAnnotation(Collection.class); ClassInfoList classList = scanResult.getClassesWithAnnotation(Collection.class);
List<Class<?>> collectionClasses = classList.loadClasses(); List<Class<?>> collectionClasses = classList.loadClasses();
List<CollectionDetails> collections = new ArrayList<>(); List<CollectionDetails> collections = new ArrayList<>();