feat: index enhancement (close #2632 pr #2636)

* feat: index paths as setting

* feat: clear index (#2632)

* feat: check indexMQ more frequently
This commit is contained in:
BoYanZh
2022-12-09 10:02:13 +08:00
committed by GitHub
parent 1f7c1b4f43
commit 6f1aeb47fd
7 changed files with 63 additions and 2 deletions

View File

@ -3,8 +3,10 @@ package handles
import (
"context"
"github.com/alist-org/alist/v3/internal/model"
"github.com/alist-org/alist/v3/internal/search"
"github.com/alist-org/alist/v3/server/common"
mapset "github.com/deckarep/golang-set/v2"
"github.com/gin-gonic/gin"
log "github.com/sirupsen/logrus"
)
@ -26,6 +28,13 @@ func BuildIndex(c *gin.Context) {
common.ErrorStrResp(c, "index is running", 400)
return
}
indexPaths := search.GetIndexPaths()
indexPaths = append(indexPaths, req.Paths...)
indexPathsSet := mapset.NewSet[string]()
for _, indexPath := range indexPaths {
indexPathsSet.Add(indexPath)
}
indexPaths = indexPathsSet.ToSlice()
ignorePaths, err := search.GetIgnorePaths()
if err != nil {
common.ErrorResp(c, err, 500)
@ -50,7 +59,7 @@ func BuildIndex(c *gin.Context) {
}
}
}
err = search.BuildIndex(context.Background(), req.Paths, ignorePaths, req.MaxDepth, true)
err = search.BuildIndex(context.Background(), indexPaths, ignorePaths, req.MaxDepth, true)
if err != nil {
log.Errorf("build index error: %+v", err)
}
@ -67,6 +76,21 @@ func StopIndex(c *gin.Context) {
common.SuccessResp(c)
}
func ClearIndex(c *gin.Context) {
if search.Running.Load() {
common.ErrorStrResp(c, "index is running", 400)
return
}
search.Clear(c)
search.WriteProgress(&model.IndexProgress{
ObjCount: 0,
IsDone: false,
LastDoneTime: nil,
Error: "",
})
common.SuccessResp(c)
}
func GetProgress(c *gin.Context) {
progress, err := search.Progress()
if err != nil {