feat: customize index max depth
Because some driver's issue may cause infinite loop
This commit is contained in:
@ -146,6 +146,7 @@ func InitialSettings() []model.SettingItem {
|
||||
{Key: conf.SearchIndex, Value: "none", Type: conf.TypeSelect, Options: "database,database_non_full_text,bleve,none", Group: model.INDEX},
|
||||
{Key: conf.AutoUpdateIndex, Value: "false", Type: conf.TypeBool, Group: model.INDEX},
|
||||
{Key: conf.IgnorePaths, Value: "", Type: conf.TypeText, Group: model.INDEX, Flag: model.PRIVATE, Help: `one path per line`},
|
||||
{Key: conf.MaxIndexDepth, Value: "20", Type: conf.TypeNumber, Group: model.INDEX, Flag: model.PRIVATE, Help: `max depth of index`},
|
||||
{Key: conf.IndexProgress, Value: "{}", Type: conf.TypeText, Group: model.SINGLE, Flag: model.PRIVATE},
|
||||
|
||||
// GitHub settings
|
||||
|
@ -44,8 +44,8 @@ const (
|
||||
// index
|
||||
SearchIndex = "search_index"
|
||||
AutoUpdateIndex = "auto_update_index"
|
||||
IndexPaths = "index_paths"
|
||||
IgnorePaths = "ignore_paths"
|
||||
MaxIndexDepth = "max_index_depth"
|
||||
|
||||
// aria2
|
||||
Aria2Uri = "aria2_uri"
|
||||
|
@ -2,7 +2,7 @@ package db
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path"
|
||||
stdpath "path"
|
||||
"strings"
|
||||
|
||||
"github.com/alist-org/alist/v3/internal/conf"
|
||||
@ -29,13 +29,13 @@ func BatchCreateSearchNodes(nodes *[]model.SearchNode) error {
|
||||
return db.CreateInBatches(nodes, 1000).Error
|
||||
}
|
||||
|
||||
func DeleteSearchNodesByParent(prefix string) error {
|
||||
prefix = utils.FixAndCleanPath(prefix)
|
||||
err := db.Where(whereInParent(prefix)).Delete(&model.SearchNode{}).Error
|
||||
func DeleteSearchNodesByParent(path string) error {
|
||||
path = utils.FixAndCleanPath(path)
|
||||
err := db.Where(whereInParent(path)).Delete(&model.SearchNode{}).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
dir, name := path.Split(prefix)
|
||||
dir, name := stdpath.Split(path)
|
||||
return db.Where(fmt.Sprintf("%s = ? AND %s = ?",
|
||||
columnName("parent"), columnName("name")),
|
||||
dir, name).Delete(&model.SearchNode{}).Error
|
||||
|
@ -217,10 +217,11 @@ func Update(parent string, objs []model.Obj) {
|
||||
}
|
||||
// build index if it's a folder
|
||||
if objs[i].IsDir() {
|
||||
dir := path.Join(parent, objs[i].GetName())
|
||||
err = BuildIndex(ctx,
|
||||
[]string{path.Join(parent, objs[i].GetName())},
|
||||
[]string{dir},
|
||||
conf.SlicesMap[conf.IgnorePaths],
|
||||
-1, false)
|
||||
setting.GetInt(conf.MaxIndexDepth, 20)-strings.Count(dir, "/"), false)
|
||||
if err != nil {
|
||||
log.Errorf("update search index error while build index: %+v", err)
|
||||
return
|
||||
|
@ -30,8 +30,8 @@ func (D DB) Get(ctx context.Context, parent string) ([]model.SearchNode, error)
|
||||
return db.GetSearchNodesByParent(parent)
|
||||
}
|
||||
|
||||
func (D DB) Del(ctx context.Context, prefix string) error {
|
||||
return db.DeleteSearchNodesByParent(prefix)
|
||||
func (D DB) Del(ctx context.Context, path string) error {
|
||||
return db.DeleteSearchNodesByParent(path)
|
||||
}
|
||||
|
||||
func (D DB) Release(ctx context.Context) error {
|
||||
|
@ -30,8 +30,8 @@ func (D DB) Get(ctx context.Context, parent string) ([]model.SearchNode, error)
|
||||
return db.GetSearchNodesByParent(parent)
|
||||
}
|
||||
|
||||
func (D DB) Del(ctx context.Context, prefix string) error {
|
||||
return db.DeleteSearchNodesByParent(prefix)
|
||||
func (D DB) Del(ctx context.Context, path string) error {
|
||||
return db.DeleteSearchNodesByParent(path)
|
||||
}
|
||||
|
||||
func (D DB) Release(ctx context.Context) error {
|
||||
|
Reference in New Issue
Block a user