refactor(internal): 优化 OSS 预签名 URL 缓存刷新任务和英雄数据缓存逻辑
- 注释掉 OSS预签名 URL 缓存刷新任务的定时执行代码 - 在 hero/hero.go 中增加对 Redis缓存和英雄数据集的非空校验 - 修改 OSS预签名 URL 生成逻辑,自动替换为 CDN 域名
This commit is contained in:
@@ -3,6 +3,7 @@ package cron
|
||||
import (
|
||||
"context"
|
||||
"epic/internal/dao"
|
||||
"epic/internal/logic/i18n"
|
||||
"epic/internal/model/entity"
|
||||
"epic/internal/service"
|
||||
"epic/internal/util"
|
||||
@@ -173,13 +174,6 @@ func (l *Logic) registerDefaultJobs(ctx context.Context) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// 每30分钟执行一次OSS预签名URL缓存刷新任务
|
||||
//if err := l.AddJob(ctx, "oss_presignurl_refresh", "0 0/30 * * * *", func() {
|
||||
// l.refreshOssPresignUrlCacheJob(ctx)
|
||||
//}); err != nil {
|
||||
// return err
|
||||
//}
|
||||
|
||||
// 每5天执行一次角色配装信息刷新任务
|
||||
if err := l.AddJob(ctx, "hero_set_refresh_5days", "0 0 0 */5 * *", func() {
|
||||
l.refreshHeroSetContent(ctx)
|
||||
@@ -187,6 +181,18 @@ func (l *Logic) registerDefaultJobs(ctx context.Context) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// 每天凌晨2点同步i18n远程翻译数据
|
||||
if err := l.AddJob(ctx, "i18n_remote_sync", "0 0 2 * * *", func() {
|
||||
g.Log().Info(ctx, "开始同步i18n远程翻译数据...")
|
||||
if err := i18n.GetI18nLogic().SyncI18nFromRemote(ctx); err != nil {
|
||||
g.Log().Error(ctx, "i18n远程翻译数据同步失败:", err)
|
||||
} else {
|
||||
g.Log().Info(ctx, "i18n远程翻译数据同步完成")
|
||||
}
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -203,7 +209,7 @@ func (l *Logic) syncDataFromThirdParty(ctx context.Context) {
|
||||
g.Log().Info(ctx, "Data sync completed")
|
||||
}
|
||||
|
||||
//同步英雄数据
|
||||
// 同步英雄数据
|
||||
func (l *Logic) syncHeroData(ctx context.Context) {
|
||||
g.Log().Info(ctx, "Starting hero data sync...")
|
||||
|
||||
@@ -215,7 +221,7 @@ func (l *Logic) syncHeroData(ctx context.Context) {
|
||||
g.Log().Info(ctx, "Hero data sync completed")
|
||||
}
|
||||
|
||||
//同步神器数据
|
||||
// 同步神器数据
|
||||
func (l *Logic) syncArtifactData(ctx context.Context) {
|
||||
g.Log().Info(ctx, "Starting artifact data sync...")
|
||||
|
||||
|
||||
@@ -732,3 +732,77 @@ func max(a, b int) int {
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
// 修复历史数据,将epic_hero_info.hero_name和epic_artifact_info.artifact_name翻译为中文(基于code匹配)
|
||||
func FixHeroAndArtifactNameToChinese(ctx context.Context) error {
|
||||
// 1. 查询i18n hero映射(code->zh)
|
||||
var heroMappings []*entity.EpicI18NMappings
|
||||
err := dao.EpicI18NMappings.Ctx(ctx).
|
||||
Where(dao.EpicI18NMappings.Columns().Language, "zh").
|
||||
Where(dao.EpicI18NMappings.Columns().Category, "hero").
|
||||
Where(dao.EpicI18NMappings.Columns().Status, 1).
|
||||
Where(dao.EpicI18NMappings.Columns().Deleted, 0).
|
||||
Scan(&heroMappings)
|
||||
if err != nil {
|
||||
return fmt.Errorf("查询i18n hero映射失败: %v", err)
|
||||
}
|
||||
heroCodeToZh := make(map[string]string)
|
||||
for _, m := range heroMappings {
|
||||
heroCodeToZh[m.Code] = m.Value
|
||||
}
|
||||
|
||||
// 2. 修复英雄表
|
||||
var heroes []*entity.EpicHeroInfo
|
||||
err = dao.EpicHeroInfo.Ctx(ctx).Scan(&heroes)
|
||||
if err != nil {
|
||||
return fmt.Errorf("查询epic_hero_info失败: %v", err)
|
||||
}
|
||||
for _, h := range heroes {
|
||||
if zh, ok := heroCodeToZh[h.HeroCode]; ok && zh != "" && zh != h.HeroName {
|
||||
_, err := dao.EpicHeroInfo.Ctx(ctx).
|
||||
Where(dao.EpicHeroInfo.Columns().HeroCode, h.HeroCode).
|
||||
Data(g.Map{dao.EpicHeroInfo.Columns().HeroName: zh}).
|
||||
Update()
|
||||
if err != nil {
|
||||
g.Log().Errorf(ctx, "更新英雄中文名失败: %s(%s) -> %s, err: %v", h.HeroName, h.HeroCode, zh, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
g.Log().Info(ctx, "epic_hero_info英雄名修复完成")
|
||||
|
||||
// 3. 查询i18n artifact映射(code->zh)
|
||||
var artifactMappings []*entity.EpicI18NMappings
|
||||
err = dao.EpicI18NMappings.Ctx(ctx).
|
||||
Where(dao.EpicI18NMappings.Columns().Language, "zh").
|
||||
Where(dao.EpicI18NMappings.Columns().Category, "artifact").
|
||||
Where(dao.EpicI18NMappings.Columns().Status, 1).
|
||||
Where(dao.EpicI18NMappings.Columns().Deleted, 0).
|
||||
Scan(&artifactMappings)
|
||||
if err != nil {
|
||||
return fmt.Errorf("查询i18n artifact映射失败: %v", err)
|
||||
}
|
||||
artifactCodeToZh := make(map[string]string)
|
||||
for _, m := range artifactMappings {
|
||||
artifactCodeToZh[m.Code] = m.Value
|
||||
}
|
||||
|
||||
// 4. 修复神器表
|
||||
var artifacts []*entity.EpicArtifactInfo
|
||||
err = dao.EpicArtifactInfo.Ctx(ctx).Scan(&artifacts)
|
||||
if err != nil {
|
||||
return fmt.Errorf("查询epic_artifact_info失败: %v", err)
|
||||
}
|
||||
for _, a := range artifacts {
|
||||
if zh, ok := artifactCodeToZh[a.ArtifactCode]; ok && zh != "" && zh != a.ArtifactName {
|
||||
_, err := dao.EpicArtifactInfo.Ctx(ctx).
|
||||
Where(dao.EpicArtifactInfo.Columns().ArtifactCode, a.ArtifactCode).
|
||||
Data(g.Map{dao.EpicArtifactInfo.Columns().ArtifactName: zh}).
|
||||
Update()
|
||||
if err != nil {
|
||||
g.Log().Errorf(ctx, "更新神器中文名失败: %s(%s) -> %s, err: %v", a.ArtifactName, a.ArtifactCode, zh, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
g.Log().Info(ctx, "epic_artifact_info神器名修复完成")
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -67,3 +67,22 @@ func TestInitI18nStaticToDB(t *testing.T) {
|
||||
}
|
||||
t.Logf("静态i18n数据导入成功,共%d条", len(i18n.I18nEnToZh))
|
||||
}
|
||||
|
||||
func TestSyncI18nFromRemote(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
logic := i18n.GetI18nLogic()
|
||||
err := logic.SyncI18nFromRemote(ctx)
|
||||
if err != nil {
|
||||
t.Fatalf("远程i18n数据同步失败: %v", err)
|
||||
}
|
||||
t.Logf("远程i18n数据同步成功")
|
||||
}
|
||||
|
||||
func TestFixHeroAndArtifactNameToChinese(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
err := FixHeroAndArtifactNameToChinese(ctx)
|
||||
if err != nil {
|
||||
t.Fatalf("修复英雄/神器中文名失败: %v", err)
|
||||
}
|
||||
t.Logf("修复英雄/神器中文名成功")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user