fix: reset index before build new one (#2471)

pull/2504/head
BoYanZh 2022-11-24 14:47:49 +08:00 committed by GitHub
parent 330a767fd7
commit 2383e851e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 6 deletions

View File

@ -53,18 +53,14 @@ type Data struct {
}
func BuildIndex(ctx context.Context, indexPaths, ignorePaths []string, maxDepth int) {
WriteProgress(&Progress{
FileCount: 0,
IsDone: false,
LastDoneTime: nil,
})
// TODO: partial remove indices
Reset()
var batchs []*bleve.Batch
var fileCount uint64 = 0
for _, indexPath := range indexPaths {
batch := func() *bleve.Batch {
batch := index.NewBatch()
// TODO: cache unchanged part
// TODO: store current progress
walkFn := func(indexPath string, info model.Obj, err error) error {
for _, avoidPath := range ignorePaths {
if indexPath == avoidPath {

View File

@ -1,6 +1,9 @@
package index
import (
"os"
"github.com/alist-org/alist/v3/internal/conf"
"github.com/blevesearch/bleve/v2"
log "github.com/sirupsen/logrus"
)
@ -28,3 +31,17 @@ func Init(indexPath *string) {
})
}
}
func Reset() {
log.Infof("Removing old index...")
err := os.RemoveAll(conf.Conf.IndexDir)
if err != nil {
log.Fatal(err)
}
Init(&conf.Conf.IndexDir)
WriteProgress(&Progress{
FileCount: 0,
IsDone: false,
LastDoneTime: nil,
})
}