mirror of
https://github.com/OpenListTeam/OpenList.git
synced 2026-10-10 04:53:09 +08:00
fix(index/meilisearch): refresh progress after update (#2628)
fix(index): refresh progress after update - 手动更新索引完成后刷新索引进度状态 - 保留现有对象计数避免引入计数差值风险 - 记录更新失败时的错误信息 Signed-off-by: jyxjjj <16695261+jyxjjj@users.noreply.github.com> Co-authored-by: Codex <267193182+codex@users.noreply.github.com>
This commit is contained in:
+23
-2
@@ -2,6 +2,7 @@ package handles
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/OpenListTeam/OpenList/v4/internal/conf"
|
"github.com/OpenListTeam/OpenList/v4/internal/conf"
|
||||||
"github.com/OpenListTeam/OpenList/v4/internal/model"
|
"github.com/OpenListTeam/OpenList/v4/internal/model"
|
||||||
@@ -55,18 +56,38 @@ func UpdateIndex(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
go func() {
|
go func() {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
progress, err := search.Progress()
|
||||||
|
if err != nil {
|
||||||
|
log.Errorf("get index progress error: %+v", err)
|
||||||
|
progress = &model.IndexProgress{}
|
||||||
|
}
|
||||||
for _, path := range req.Paths {
|
for _, path := range req.Paths {
|
||||||
err := search.Del(ctx, path)
|
err = search.Del(ctx, path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("delete index on %s error: %+v", path, err)
|
log.Errorf("delete index on %s error: %+v", path, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
err := search.BuildIndex(context.Background(), req.Paths,
|
err = search.BuildIndex(context.Background(), req.Paths,
|
||||||
conf.SlicesMap[conf.IgnorePaths], req.MaxDepth, false)
|
conf.SlicesMap[conf.IgnorePaths], req.MaxDepth, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("update index error: %+v", err)
|
log.Errorf("update index error: %+v", err)
|
||||||
|
now := time.Now()
|
||||||
|
search.WriteProgress(&model.IndexProgress{
|
||||||
|
ObjCount: progress.ObjCount,
|
||||||
|
IsDone: true,
|
||||||
|
LastDoneTime: &now,
|
||||||
|
Error: err.Error(),
|
||||||
|
})
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
now := time.Now()
|
||||||
|
search.WriteProgress(&model.IndexProgress{
|
||||||
|
ObjCount: progress.ObjCount,
|
||||||
|
IsDone: true,
|
||||||
|
LastDoneTime: &now,
|
||||||
|
Error: "",
|
||||||
|
})
|
||||||
}()
|
}()
|
||||||
common.SuccessResp(c)
|
common.SuccessResp(c)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user