Skip to content

Commit

Permalink
fix: 修正帮助文档无法加载指令相关帮助文档的问题,并补充部分日志
Browse files Browse the repository at this point in the history
(cherry picked from commit 3afa24a3acc31ad01f443c092ced3685e1b3c4f4)
  • Loading branch information
PaienNate committed Jan 11, 2025
1 parent 23b8ab8 commit 4a8a9e3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
18 changes: 15 additions & 3 deletions dice/dice_help.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,13 @@ func (m *HelpManager) Load() {
})
m.HelpDocTree = append(m.HelpDocTree, &child)
}
_ = m.AddItemApply(true)
// TODO: Hack mode。此处是故意为之,因为帮助文档还包含对于指令的帮助部分,他们在帮助文档之后加载。如果在此处设置true,后续将无法加载
// TODO: 或许可以考虑提供一个函数专门加载指令,或者不再提供AddItemApply函数 end=true,直接循环使用同一个batch。
// TODO: 不修改下层逻辑的原因是可以以后开发复用我封装的模块。
err = m.AddItemApply(false)
if err != nil {
log.Errorf("unable to add item apply to search engine: %v", err)
}
m.CurID = m.searchEngine.GetTotalID()
elapsed := time.Since(start) // 计算执行时间
log.Infof("帮助文档加载完毕,共耗费时间: %s 共计加载条目:%d\n", elapsed, m.CurID)
Expand Down Expand Up @@ -418,12 +424,15 @@ func (dm *DiceManager) AddHelpWithDice(dice *Dice) {
if content == "" {
content = v.ShortHelp
}
_ = m.AddItem(docengine.HelpTextItem{
err := m.AddItem(docengine.HelpTextItem{
Group: HelpBuiltinGroup,
Title: k,
Content: content,
PackageName: packageName,
})
if err != nil {
log.Errorf("AddHelpWithDice AddItem err:%v", err)
}
}
}

Expand All @@ -437,7 +446,10 @@ func (dm *DiceManager) AddHelpWithDice(dice *Dice) {
})
addCmdMap(i.Name, i.CmdMap)
}
_ = m.AddItemApply(false)
err := m.AddItemApply(false)
if err != nil {
log.Errorf("AddHelpWithDice AddItemApply err:%v", err)
}
}

func (m *HelpManager) AddItem(item docengine.HelpTextItem) error {
Expand Down
4 changes: 1 addition & 3 deletions dice/docengine/bleve.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ func (d *BleveSearchEngine) AddItem(item HelpTextItem) (string, error) {
// AddItemApply 这里认为是真正执行插入文档的逻辑
// 由于现在已经将执行函数改为了可按文件执行,所以可以按文件进行Apply,这应当不会有太大的量级。
// end代表是否是最后一次执行,一般用在所有的数据都处理完之后,关闭逻辑的时候使用,如bleve batch重复利用后最后销毁
// TODO: 似乎很奇怪,这家伙貌似不会回收内存的吗?
func (d *BleveSearchEngine) AddItemApply(end bool) error {
if d.batch != nil {
// 执行batch
Expand All @@ -130,11 +129,10 @@ func (d *BleveSearchEngine) AddItemApply(end bool) error {
}
// 如果是最后一批
if end {
// 销毁batch
d.batch.Reset()
d.batch = nil
} else {
// 否则重置batch
// 否则仅重置batch
d.batch.Reset()
}
return err
Expand Down

0 comments on commit 4a8a9e3

Please sign in to comment.