feat: cache dashboard site summary
This commit is contained in:
parent
13d36c25d4
commit
0c9383e329
1 changed files with 28 additions and 18 deletions
|
@ -70,6 +70,21 @@ func (service *BatchSettingChangeService) Change() serializer.Response {
|
|||
|
||||
// Summary 获取站点统计概况
|
||||
func (service *NoParamService) Summary() serializer.Response {
|
||||
// 获取版本信息
|
||||
versions := map[string]string{
|
||||
"backend": conf.BackendVersion,
|
||||
"db": conf.RequiredDBVersion,
|
||||
"commit": conf.LastCommit,
|
||||
"is_pro": conf.IsPro,
|
||||
}
|
||||
|
||||
if res, ok := cache.Get("admin_summary"); ok {
|
||||
resMap := res.(map[string]interface{})
|
||||
resMap["version"] = versions
|
||||
resMap["siteURL"] = model.GetSettingByName("siteURL")
|
||||
return serializer.Response{Data: resMap}
|
||||
}
|
||||
|
||||
// 统计每日概况
|
||||
total := 12
|
||||
files := make([]int, total)
|
||||
|
@ -98,16 +113,7 @@ func (service *NoParamService) Summary() serializer.Response {
|
|||
model.DB.Model(&model.Share{}).Where("password = ?", "").Count(&publicShareTotal)
|
||||
model.DB.Model(&model.Share{}).Where("password <> ?", "").Count(&secretShareTotal)
|
||||
|
||||
// 获取版本信息
|
||||
versions := map[string]string{
|
||||
"backend": conf.BackendVersion,
|
||||
"db": conf.RequiredDBVersion,
|
||||
"commit": conf.LastCommit,
|
||||
"is_pro": conf.IsPro,
|
||||
}
|
||||
|
||||
return serializer.Response{
|
||||
Data: map[string]interface{}{
|
||||
resp := map[string]interface{}{
|
||||
"date": date,
|
||||
"files": files,
|
||||
"users": users,
|
||||
|
@ -118,6 +124,10 @@ func (service *NoParamService) Summary() serializer.Response {
|
|||
"userTotal": userTotal,
|
||||
"publicShareTotal": publicShareTotal,
|
||||
"secretShareTotal": secretShareTotal,
|
||||
},
|
||||
}
|
||||
|
||||
cache.Set("admin_summary", resp, 86400)
|
||||
return serializer.Response{
|
||||
Data: resp,
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue