diff --git a/src/Operation.php b/src/Operation.php index 89b106997..adbb26eb1 100644 --- a/src/Operation.php +++ b/src/Operation.php @@ -809,9 +809,23 @@ public static function discover($discoverable) return; } - $namespace = null; $reflectionClass = new ReflectionClass($discoverable); + // Fast path: skip full discovery if no methods have LodataOperation attributes. + // This avoids expensive reflection loops for Eloquent models that don't define operations. + $hasAnyOperations = false; + foreach ($reflectionClass->getMethods(ReflectionMethod::IS_PUBLIC) as $method) { + if ($method->getAttributes(LodataOperation::class, ReflectionAttribute::IS_INSTANCEOF)) { + $hasAnyOperations = true; + break; + } + } + if (!$hasAnyOperations) { + return; + } + + $namespace = null; + /** @var ReflectionAttribute $namespaceAttribute */ $namespaceAttribute = Arr::first($reflectionClass->getAttributes(LodataNamespace::class)); if ($namespaceAttribute) {