perf/security: V0.9.5-0.9.6 db_pending_upgrades 缓存 + config 凭据外置
- V0.9.5 (P3): db_pending_upgrades() 加 static 请求内缓存,同请求只算一次 - V0.9.6 (安全): config.php 移除明文密码,改从 gitignored 的 config.secret.php 或 环境变量读取;新增 config.secret.php.example 模板;.gitignore 忽略 config/config.secret.php (修复 Webhook reset 反复覆盖明文凭据的隐患;服务器部署前需自建 config.secret.php)
This commit is contained in:
+8
-3
@@ -544,12 +544,15 @@ if (!function_exists('site_url')) {
|
||||
*/
|
||||
function db_pending_upgrades(): int
|
||||
{
|
||||
// V0.9.5:请求内缓存(一次请求内多次调用只算一次),避免每后台页重复 glob+md5_file+SELECT
|
||||
static $cache = null;
|
||||
if ($cache !== null) return $cache;
|
||||
try {
|
||||
if (\Core\Db::driver() !== 'mysql') return 0;
|
||||
if (\Core\Db::driver() !== 'mysql') { $cache = 0; return 0; }
|
||||
$dir = db_upgrade_dir();
|
||||
if (!is_dir($dir)) return 0;
|
||||
if (!is_dir($dir)) { $cache = 0; return 0; }
|
||||
$files = glob($dir . '/*.sql') ?: [];
|
||||
if (!$files) return 0;
|
||||
if (!$files) { $cache = 0; return 0; }
|
||||
\Core\Installer::ensureUpgradeLog();
|
||||
$applied = \Core\Db::query("SELECT file, hash FROM db_upgrades")->fetchAll(\PDO::FETCH_KEY_PAIR);
|
||||
$n = 0;
|
||||
@@ -560,8 +563,10 @@ if (!function_exists('site_url')) {
|
||||
$n++;
|
||||
}
|
||||
}
|
||||
$cache = $n;
|
||||
return $n;
|
||||
} catch (\Throwable $e) {
|
||||
$cache = 0;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user