perf: 性能优化与错误修复

- 修复 N+1 查询: users/devices/agents 批量 GROUP BY 替代循环查询
- 添加分页: cards/finance/agents/devices API
- Redis 初始化根据安装配置 redis.enabled 决定是否连接
- 修复 DefaultVal 解析错误: 使用 sql.NullString 处理 NULL 值
- Dashboard 优化: 替换 ECharts 世界地图为 Chart.js 环形饼图
- 适配前端 cards 页面新 API 响应格式
- 添加数据库索引优化查询性能
- 实现可配置的数据清理定时任务
This commit is contained in:
2026-05-06 19:19:02 +08:00
parent 98986b0eb7
commit 086c5c6573
27 changed files with 843 additions and 467 deletions
+10 -4
View File
@@ -9,6 +9,7 @@ package database
import (
"context"
"database/sql"
"fmt"
"log"
"os"
@@ -162,7 +163,7 @@ func runMigrations() {
Name string
Type string
NotNull int
DefaultVal interface{}
DefaultVal sql.NullString
PK int
}
DB.Raw("PRAGMA table_info(applications)").Scan(&columns)
@@ -171,13 +172,12 @@ func runMigrations() {
log.Printf(" - %s (%s)\n", col.Name, col.Type)
}
// 检查app_users表结构
var appUserColumns []struct {
CID int
Name string
Type string
NotNull int
DefaultVal interface{}
DefaultVal sql.NullString
PK int
}
DB.Raw("PRAGMA table_info(app_users)").Scan(&appUserColumns)
@@ -272,7 +272,7 @@ func runMigrations() {
Name string
Type string
NotNull int
DefaultVal interface{}
DefaultVal sql.NullString
PK int
}
DB.Raw("PRAGMA table_info(risk_control_rules)").Scan(&riskControlTableInfo)
@@ -710,6 +710,12 @@ func initDocData() {
// initRedis 初始化Redis连接
func initRedis() {
if !config.GetBool("redis.enabled") {
log.Println("Redis is disabled by configuration, skipping connection")
RDB = nil
return
}
RDB = redis.NewClient(&redis.Options{
Addr: fmt.Sprintf("%s:%s", config.GetString("redis.host"), config.GetString("redis.port")),
Password: config.GetString("redis.password"),