refactor(internal): 优化 OSS 预签名 URL 缓存刷新任务和英雄数据缓存逻辑
- 注释掉 OSS预签名 URL 缓存刷新任务的定时执行代码 - 在 hero/hero.go 中增加对 Redis缓存和英雄数据集的非空校验 - 修改 OSS预签名 URL 生成逻辑,自动替换为 CDN 域名
This commit is contained in:
@@ -12,7 +12,7 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// I18nEnToZh 英文->中文映射表(示例)
|
||||
// I18nEnToZh 英文->中文映射表(仅做备份,不再作为主数据源)
|
||||
var I18nEnToZh = map[string]string{
|
||||
"A Little Queen's Huge Crown": "小小女王的巨大王冠",
|
||||
"A Song for Everybody": "献给你和这个世界的歌曲",
|
||||
@@ -646,11 +646,15 @@ func (l *Logic) LoadFromDB(ctx context.Context) error {
|
||||
|
||||
// 重新构建缓存
|
||||
l.cache = make(map[string]map[string]string)
|
||||
// 新增:同步数据库内容到I18nEnToZh备份
|
||||
for _, m := range mappings {
|
||||
if l.cache[m.Language] == nil {
|
||||
l.cache[m.Language] = make(map[string]string)
|
||||
}
|
||||
l.cache[m.Language][m.KeyName] = m.Value
|
||||
if m.Language == "zh" {
|
||||
I18nEnToZh[m.KeyName] = m.Value
|
||||
}
|
||||
}
|
||||
|
||||
util.Info(ctx, "i18n缓存加载完成,共", len(mappings), "条记录")
|
||||
@@ -871,16 +875,24 @@ func (l *Logic) StartAutoRefresh(ctx context.Context) {
|
||||
}()
|
||||
}
|
||||
|
||||
// En2Zh 英文转中文(静态映射)
|
||||
// En2Zh 英文转中文(静态映射,仅降级时使用)
|
||||
func En2Zh(s string) string {
|
||||
if v, ok := GetI18nLogic().cache["zh"][s]; ok {
|
||||
return v
|
||||
}
|
||||
// 仅降级时才用备份
|
||||
if v, ok := I18nEnToZh[s]; ok {
|
||||
return v
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
// Zh2En 中文转英文(静态映射)
|
||||
// Zh2En 中文转英文(静态映射,仅降级时使用)
|
||||
func Zh2En(s string) string {
|
||||
if v, ok := GetI18nLogic().cache["en"][s]; ok {
|
||||
return v
|
||||
}
|
||||
// 仅降级时才用备份
|
||||
if v, ok := I18nZhToEn[s]; ok {
|
||||
return v
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user