fix(server): 补上 DatabaseManager 缺失的连接池与性能方法
DatabaseManager 类从未定义 getConnectionPoolStatus / getPerformanceMetrics, 但有 4 个接口直接调用它们,导致运行时 TypeError 并返回 500: GET /api/admin/database/pool-status GET /api/admin/database/performance GET /api/system/status POST /api/system/reconnect 两个函数本就实现在 utils/database-health.ts(getConnectionPoolStatus / getDatabaseMetrics),这里补上委托方法,调用点无需改动。 验证:用项目的 .nuxt/tsconfig.server.json 做 A/B 类型检查, 改动前有 4 处 'Property does not exist on type DatabaseManager', 改动后全部消失(总报错数 682 -> 678)。
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
import { db, getConnectionStatus } from '~/drizzle/db'
|
import { db, getConnectionStatus } from '~/drizzle/db'
|
||||||
import { sql } from 'drizzle-orm'
|
import { sql } from 'drizzle-orm'
|
||||||
|
import { getConnectionPoolStatus, getDatabaseMetrics } from './database-health'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 数据库管理器
|
* 数据库管理器
|
||||||
@@ -194,6 +195,30 @@ export class DatabaseManager {
|
|||||||
lastHealthCheck: this.healthCheckCache ? new Date(this.healthCheckCache.timestamp) : null
|
lastHealthCheck: this.healthCheckCache ? new Date(this.healthCheckCache.timestamp) : null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 连接池状态(最大/活跃/总连接数、使用率)。
|
||||||
|
*
|
||||||
|
* 实现位于 utils/database-health.ts。此前有 3 个接口直接调用
|
||||||
|
* databaseManager.getConnectionPoolStatus(),但本类从未定义该方法,
|
||||||
|
* 导致以下接口全部 500(TypeError: not a function):
|
||||||
|
* GET /api/admin/database/pool-status
|
||||||
|
* POST /api/system/reconnect
|
||||||
|
* GET /api/system/status
|
||||||
|
*/
|
||||||
|
async getConnectionPoolStatus() {
|
||||||
|
return getConnectionPoolStatus()
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据库性能指标。
|
||||||
|
*
|
||||||
|
* 同上:GET /api/admin/database/performance 调用 databaseManager.getPerformanceMetrics(),
|
||||||
|
* 而本类没有该方法,接口一直 500。实现位于 utils/database-health.ts 的 getDatabaseMetrics。
|
||||||
|
*/
|
||||||
|
async getPerformanceMetrics() {
|
||||||
|
return getDatabaseMetrics()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 导出单例实例
|
// 导出单例实例
|
||||||
|
|||||||
Reference in New Issue
Block a user