From 6616e967246986a7bb83ae87ea45773a074617f6 Mon Sep 17 00:00:00 2001 From: wolfcode <37436228+wolf-leo@users.noreply.github.com> Date: Tue, 22 Oct 2024 11:31:06 +0800 Subject: [PATCH] perf(middleware): optimize system log middleware for performance - Remove redundant code for checking ignoreLog property - Consolidate logic to check ignoreLog property in a single location - Improve readability and maintainability of the code Signed-off-by: wolfcode <37436228+wolf-leo@users.noreply.github.com> --- app/admin/middleware/SystemLog.php | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/app/admin/middleware/SystemLog.php b/app/admin/middleware/SystemLog.php index 838c761..f7444c3 100644 --- a/app/admin/middleware/SystemLog.php +++ b/app/admin/middleware/SystemLog.php @@ -48,15 +48,6 @@ class SystemLog if ($request->isAjax()) { if (in_array($method, ['post', 'put', 'delete'])) { - $controller = $request->controller(); - if (str_contains($controller, '.')) $controller = str_replace('.', '\\', $controller); - $action = $request->action(); - $controllerClass = 'app\\admin\\controller\\' . $controller; - $classObj = new ReflectionClass($controllerClass); - $properties = $classObj->getDefaultProperties(); - $ignoreLog = $properties['ignoreLog'] ?? []; - if (in_array($action, $ignoreLog)) return $response; - $title = ''; try { $pathInfo = $request->pathinfo(); @@ -68,7 +59,10 @@ class SystemLog if ($_name && $_controller && $_action) { $className = "app\admin\controller\\{$_name}\\{$_controller}"; $reflectionClass = new \ReflectionClass($className); - $parser = new DocParser(); + $properties = $reflectionClass->getDefaultProperties(); + $ignoreLog = $properties['ignoreLog'] ?? []; + if (in_array($_action, $ignoreLog)) return $response; + $parser = new DocParser(); $parser->setIgnoreNotImportedAnnotations(true); $reader = new AnnotationReader($parser); $controllerAnnotation = $reader->getClassAnnotation($reflectionClass, ControllerAnnotation::class);