修改获取dashboard统计信息,添加缓存每10s获取一次,加快响应速度
This commit is contained in:
parent
d3d3e6f594
commit
d47e4f7276
|
|
@ -414,15 +414,29 @@ func SendMailTool(c *gin.Context) {
|
||||||
|
|
||||||
func DashBoardStatistics(c *gin.Context) {
|
func DashBoardStatistics(c *gin.Context) {
|
||||||
//用户统计信息
|
//用户统计信息
|
||||||
rbase := service.GetBaseDashboardInfo()
|
|
||||||
var resp proto.DashBoardStatisticsResp
|
var resp proto.DashBoardStatisticsResp
|
||||||
//获取最近7天的统计信息
|
|
||||||
sWeek, _ := service.GetRecent7DaysMessageSessionCount()
|
key := "dashboard_statistics_info"
|
||||||
//模型统计信息
|
if worker.IsContainKey(key) {
|
||||||
modelst, _ := service.GetModelUsageStatistics()
|
//从redis获取
|
||||||
resp.DashBoardStatisticsSt = rbase
|
dashboardStatisticsInfo := worker.GetRedis(key)
|
||||||
resp.DashBoardStatisticsWeekSt = sWeek
|
if dashboardStatisticsInfo != "" {
|
||||||
resp.DashBoardStatisticsModelSt = modelst
|
err := json.Unmarshal([]byte(dashboardStatisticsInfo), &resp)
|
||||||
|
if err != nil {
|
||||||
|
log.Println("get redis dashboard statistics info error:", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
service.SetDashboardInfoToRedis() //统计dashboard信息保存在redis中
|
||||||
|
dashboardStatisticsInfo := worker.GetRedis(key)
|
||||||
|
if dashboardStatisticsInfo != "" {
|
||||||
|
err := json.Unmarshal([]byte(dashboardStatisticsInfo), &resp)
|
||||||
|
if err != nil {
|
||||||
|
log.Println("get redis dashboard statistics info error:", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
c.JSON(http.StatusOK, gin.H{"code": proto.SuccessCode, "message": "success", "data": resp})
|
c.JSON(http.StatusOK, gin.H{"code": proto.SuccessCode, "message": "success", "data": resp})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
||||||
3
main.go
3
main.go
|
|
@ -211,7 +211,8 @@ func myTask() {
|
||||||
}
|
}
|
||||||
//其它定时任务-通用
|
//其它定时任务-通用
|
||||||
RunGeneralCron()
|
RunGeneralCron()
|
||||||
service.AddKnowledgeBaseServer() //将配置文件中支持的知识库处理服务器添加到集合
|
service.AddKnowledgeBaseServer() //将配置文件中支持的知识库处理服务器添加到集合
|
||||||
|
service.SetDashboardInfoToRedis() //统计dashboard信息保存在redis中
|
||||||
}
|
}
|
||||||
|
|
||||||
func ReadConfigToSetSystem() {
|
func ReadConfigToSetSystem() {
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"StuAcaWorksAI/dao"
|
"StuAcaWorksAI/dao"
|
||||||
"StuAcaWorksAI/proto"
|
"StuAcaWorksAI/proto"
|
||||||
"StuAcaWorksAI/worker"
|
"StuAcaWorksAI/worker"
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
|
@ -172,3 +173,31 @@ func GetModelUsageStatistics() ([]proto.MessageModelIDCountSt, error) {
|
||||||
}
|
}
|
||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 定时任务统计dashboard信息保存在redis中
|
||||||
|
func SetDashboardInfoToRedis() {
|
||||||
|
//用户统计信息
|
||||||
|
rbase := GetBaseDashboardInfo()
|
||||||
|
var resp proto.DashBoardStatisticsResp
|
||||||
|
//获取最近7天的统计信息
|
||||||
|
sWeek, _ := GetRecent7DaysMessageSessionCount()
|
||||||
|
//模型统计信息
|
||||||
|
modelst, _ := GetModelUsageStatistics()
|
||||||
|
resp.DashBoardStatisticsSt = rbase
|
||||||
|
resp.DashBoardStatisticsWeekSt = sWeek
|
||||||
|
resp.DashBoardStatisticsModelSt = modelst
|
||||||
|
|
||||||
|
respStr, err := json.Marshal(resp)
|
||||||
|
if err != nil {
|
||||||
|
log.Println("set dashboard info to redis error:", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
key := "dashboard_statistics_info"
|
||||||
|
//将数据存入redis
|
||||||
|
isSet := worker.SetRedisWithExpire(key, string(respStr), time.Duration(1)*time.Hour)
|
||||||
|
if !isSet {
|
||||||
|
log.Println("set dashboard info to redis error")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue