feat(skill): optimize loadCandidateSkills to use batch retrieval for skill definitions

This commit is contained in:
mlogclub
2026-04-17 17:27:33 +08:00
parent c396a4a5e3
commit 81056a61a1
2 changed files with 18 additions and 12 deletions
+3 -12
View File
@@ -25,21 +25,12 @@ func (l *candidateLoader) loadCandidateSkills(aiAgent *models.AIAgent) []models.
return nil
}
skillIDs := utils.SplitInt64s(aiAgent.SkillIDs)
if len(skillIDs) == 0 {
return nil
}
skills := repositories.SkillDefinitionRepository.GetByIDs(sqls.DB(), skillIDs)
ret := make([]models.SkillDefinition, 0, len(skillIDs))
for _, id := range skillIDs {
// TODO 这里批量查询一下,批量查询返回数据的顺序需要保证和skillIDs一致
skill := l.getSkillByID(id)
if skill == nil || skill.Status != enums.StatusOk {
continue
if skill, ok := skills[id]; ok && skill.Status == enums.StatusOk {
ret = append(ret, skill)
}
ret = append(ret, *skill)
}
return ret
}
func (l *candidateLoader) getSkillByID(id int64) *models.SkillDefinition {
return repositories.SkillDefinitionRepository.Get(sqls.DB(), id)
}