From 487a99d2a74c4a3ca5e7becdeca300b45e74dbff Mon Sep 17 00:00:00 2001 From: liugang Date: Thu, 26 Dec 2024 16:27:47 +0800 Subject: [PATCH] + [refac] cache unique indexes. --- lib/base/dao/dao.class.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/base/dao/dao.class.php b/lib/base/dao/dao.class.php index 7360a7fa33..bb475e0278 100644 --- a/lib/base/dao/dao.class.php +++ b/lib/base/dao/dao.class.php @@ -218,6 +218,15 @@ class baseDAO */ public static $tablesDesc = array(); + /** + * 缓存已经查询过的唯一索引。 + * Cache unique indexes. + * + * @var array + * @access private + */ + private static $uniqueIndexes = []; + /** * 构造方法。 * The construct method. @@ -1052,10 +1061,15 @@ class baseDAO */ private function getUniqueIndexes($table) { + if(isset(dao::$uniqueIndexes[$table])) return dao::$uniqueIndexes[$table]; + $indexes = []; $table = trim($table, '`'); $rows = $this->select('INDEX_NAME, COLUMN_NAME')->from('INFORMATION_SCHEMA.STATISTICS')->where('TABLE_SCHEMA')->eq($this->config->db->name)->andWhere('TABLE_NAME')->eq($table)->andWhere('NON_UNIQUE')->eq(0)->andWhere('INDEX_NAME')->ne('PRIMARY')->query()->fetchAll(); foreach($rows as $row) $indexes[$row->INDEX_NAME][] = $row->COLUMN_NAME; + + dao::$uniqueIndexes[$table] = $indexes; + return $indexes; }