mirror of https://github.com/Xhofe/alist
				
				
				
			fix: reset index before build new one (#2471)
							parent
							
								
									330a767fd7
								
							
						
					
					
						commit
						2383e851e2
					
				| 
						 | 
				
			
			@ -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 {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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,
 | 
			
		||||
	})
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue