From 9307e724a9ca2538aa400e317f0b119b29612090 Mon Sep 17 00:00:00 2001 From: wolfcode <37436228+wolf-leo@users.noreply.github.com> Date: Tue, 22 Oct 2024 11:54:59 +0800 Subject: [PATCH] refactor(SystemLogService): optimize detectTable method and improve code quality - Remove unnecessary return type annotation in instance method - Add type hint for SystemLogService instance - Use variable for cache key to improve code readability - Update cache key name for consistency Signed-off-by: wolfcode <37436228+wolf-leo@users.noreply.github.com> --- app/admin/service/SystemLogService.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/admin/service/SystemLogService.php b/app/admin/service/SystemLogService.php index 623b309..4e104fb 100644 --- a/app/admin/service/SystemLogService.php +++ b/app/admin/service/SystemLogService.php @@ -44,14 +44,13 @@ class SystemLogService $this->tablePrefix = Config::get('database.connections.mysql.prefix'); $this->tableSuffix = date('Ym', time()); $this->tableName = "{$this->tablePrefix}system_log_{$this->tableSuffix}"; - return $this; } /** * 获取实例对象 - * @return SystemLogService|object + * @return SystemLogService */ - public static function instance() + public static function instance(): SystemLogService { if (is_null(self::$instance)) { self::$instance = new static(); @@ -85,15 +84,16 @@ class SystemLogService */ public function detectTable(): bool { + $_key = "system_log_{$this->tableName}_table"; // 手动删除日志表时候 记得清除缓存 - $isset = Cache::get("systemLog{$this->tableName}Table"); + $isset = Cache::get($_key); if ($isset) return true; $check = Db::query("show tables like '{$this->tableName}'"); if (empty($check)) { $sql = $this->getCreateSql(); Db::execute($sql); } - Cache::set("system_log_{$this->tableName}_table", !empty($check)); + Cache::set($_key, !empty($check)); return true; }