feat(talk): 优化采集逻辑并移除冗余字典服务调用
- 移除了 talk.go 中对 dict 模块的依赖,直接使用配置中的 ItemID - 修改了 talkconfig.go 中的 ItemID 类型为 uint32,提升一致性 - 调整 talk.go 和 talkconfig.go 的缓存获取方式,增强性能 - 更新了 pet_fusion_material_service.go 中字典服务调用方法 - 修复 talk 模型中 TalkID 字段的唯一索引问题 - 日志记录由 Error 改为 Info,避免误导性
This commit is contained in:
@@ -44,7 +44,7 @@ func (s *DictInfoService) Data(ctx context.Context, types []string) (data interf
|
||||
data = g.Map{}
|
||||
for _, v := range typeData {
|
||||
m := cool.DBM(dictInfoModel)
|
||||
result, err := m.Where("typeId", v["id"]).Fields("id", "name", "parentId", "typeId").Order("ordernum asc").All()
|
||||
result, err := m.Where("typeId", v["id"]).FieldsEx("id", "remark").Order("ordernum asc").All()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -55,7 +55,8 @@ func (s *DictInfoService) Data(ctx context.Context, types []string) (data interf
|
||||
}
|
||||
return
|
||||
}
|
||||
func (s *DictInfoService) DataRemark(types string) (data map[uint32]model.DictInfo) {
|
||||
|
||||
func (s *DictInfoService) GetData(types string) (data map[uint32]model.DictInfo) {
|
||||
var (
|
||||
dictInfoModel = model.NewDictInfo()
|
||||
dictTypeModel = model.NewDictType()
|
||||
@@ -75,35 +76,7 @@ func (s *DictInfoService) DataRemark(types string) (data map[uint32]model.DictIn
|
||||
m.Where("typeId", ty.ID).Scan(&ress)
|
||||
fusions := utils.ToMap(ress, func(t model.DictInfo) uint32 {
|
||||
|
||||
return gconv.Uint32(t.Remark) //物品id转id
|
||||
})
|
||||
return fusions, nil
|
||||
}, 0)
|
||||
|
||||
return ret.Interface().(map[uint32]model.DictInfo)
|
||||
|
||||
}
|
||||
func (s *DictInfoService) DataID(types string) (data map[uint32]model.DictInfo) {
|
||||
var (
|
||||
dictInfoModel = model.NewDictInfo()
|
||||
dictTypeModel = model.NewDictType()
|
||||
)
|
||||
ret, _ := cacheDict.GetOrSetFunc(context.Background(), types, func(context.Context) (interface{}, error) {
|
||||
// 如果typeData为空, 则返回空
|
||||
var ty *model.DictType
|
||||
mType := cool.DBM(dictTypeModel)
|
||||
mType.Where("key in (?)", types).Scan(&ty)
|
||||
|
||||
// 如果typeData为空, 则返回空
|
||||
if ty == nil {
|
||||
return []model.DictInfo{}, nil
|
||||
}
|
||||
m := cool.DBM(dictInfoModel)
|
||||
var ress []model.DictInfo
|
||||
m.Where("typeId", ty.ID).Scan(&ress)
|
||||
fusions := utils.ToMap(ress, func(t model.DictInfo) uint32 {
|
||||
|
||||
return gconv.Uint32(t.ID) //物品id转id
|
||||
return gconv.Uint32(t.Value) //物品id转id
|
||||
})
|
||||
return fusions, nil
|
||||
}, 0)
|
||||
|
||||
Reference in New Issue
Block a user