Skip to content

Commit ae4950e

Browse files
committed
feat: embed group_rank_info.json and enhance cache control handling
1 parent abe72e3 commit ae4950e

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

internal/handler/group_rank_info.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,34 @@ package handler
33
import (
44
"github.com/gin-gonic/gin"
55
"github.com/scutrobotlab/rm-schedule/internal/job"
6+
"github.com/scutrobotlab/rm-schedule/internal/static"
67
"github.com/scutrobotlab/rm-schedule/internal/svc"
78
)
89

910
const (
10-
groupRankInfoCacheControl = "public, max-age=5"
11+
GroupRankInfoDebug = false
12+
GroupRankInfoCacheControl = "public, max-age=5"
1113
)
1214

1315
func GroupRankInfoHandler(c *gin.Context) {
16+
if GroupRankInfoDebug {
17+
c.Header("Cache-Control", "no-cache")
18+
c.Data(200, "application/json", static.GroupRankInfoBytes)
19+
return
20+
}
21+
1422
if c.GetHeader("Tencent-Acceleration-Domain-Name") != "" {
15-
c.Header("Cache-Control", groupRankInfoCacheControl)
23+
c.Header("Cache-Control", GroupRankInfoCacheControl)
1624
c.Redirect(301, job.GroupRankInfoUrl)
1725
return
1826
}
1927

2028
if cached, b := svc.Cache.Get("group_rank_info"); b {
21-
c.Header("Cache-Control", groupRankInfoCacheControl)
29+
c.Header("Cache-Control", GroupRankInfoCacheControl)
2230
c.Data(200, "application/json", cached.([]byte))
2331
return
2432
}
2533

26-
c.Header("Cache-Control", groupRankInfoCacheControl)
34+
c.Header("Cache-Control", GroupRankInfoCacheControl)
2735
c.JSON(500, gin.H{"code": -1, "msg": "Failed to get group rank info"})
2836
}

internal/static/load_embed.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,6 @@ var RankScoreBytes []byte
1010

1111
//go:embed schedule.json
1212
var ScheduleBytes []byte
13+
14+
//go:embed group_rank_info.json
15+
var GroupRankInfoBytes []byte

0 commit comments

Comments
 (0)