Skip to content

Commit

Permalink
feat: cache dashboard site summary
Browse files Browse the repository at this point in the history
  • Loading branch information
HFO4 committed Apr 19, 2022
1 parent 13d36c2 commit 0c9383e
Showing 1 changed file with 28 additions and 18 deletions.
46 changes: 28 additions & 18 deletions service/admin/site.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -98,26 +113,21 @@ 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,
resp := map[string]interface{}{
"date": date,
"files": files,
"users": users,
"shares": shares,
"version": versions,
"siteURL": model.GetSettingByName("siteURL"),
"fileTotal": fileTotal,
"userTotal": userTotal,
"publicShareTotal": publicShareTotal,
"secretShareTotal": secretShareTotal,
}

cache.Set("admin_summary", resp, 86400)
return serializer.Response{
Data: map[string]interface{}{
"date": date,
"files": files,
"users": users,
"shares": shares,
"version": versions,
"siteURL": model.GetSettingByName("siteURL"),
"fileTotal": fileTotal,
"userTotal": userTotal,
"publicShareTotal": publicShareTotal,
"secretShareTotal": secretShareTotal,
},
Data: resp,
}
}

0 comments on commit 0c9383e

Please sign in to comment.