fix: reset index before build new one (#2471)
This commit is contained in:
parent
330a767fd7
commit
2383e851e2
@ -53,18 +53,14 @@ type Data struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func BuildIndex(ctx context.Context, indexPaths, ignorePaths []string, maxDepth int) {
|
func BuildIndex(ctx context.Context, indexPaths, ignorePaths []string, maxDepth int) {
|
||||||
WriteProgress(&Progress{
|
// TODO: partial remove indices
|
||||||
FileCount: 0,
|
Reset()
|
||||||
IsDone: false,
|
|
||||||
LastDoneTime: nil,
|
|
||||||
})
|
|
||||||
var batchs []*bleve.Batch
|
var batchs []*bleve.Batch
|
||||||
var fileCount uint64 = 0
|
var fileCount uint64 = 0
|
||||||
for _, indexPath := range indexPaths {
|
for _, indexPath := range indexPaths {
|
||||||
batch := func() *bleve.Batch {
|
batch := func() *bleve.Batch {
|
||||||
batch := index.NewBatch()
|
batch := index.NewBatch()
|
||||||
// TODO: cache unchanged part
|
// TODO: cache unchanged part
|
||||||
// TODO: store current progress
|
|
||||||
walkFn := func(indexPath string, info model.Obj, err error) error {
|
walkFn := func(indexPath string, info model.Obj, err error) error {
|
||||||
for _, avoidPath := range ignorePaths {
|
for _, avoidPath := range ignorePaths {
|
||||||
if indexPath == avoidPath {
|
if indexPath == avoidPath {
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
package index
|
package index
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/alist-org/alist/v3/internal/conf"
|
||||||
"github.com/blevesearch/bleve/v2"
|
"github.com/blevesearch/bleve/v2"
|
||||||
log "github.com/sirupsen/logrus"
|
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,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user