fix(index): update indexes in database
This commit is contained in:
parent
dda1da4576
commit
f1a9b68022
@ -2,8 +2,10 @@ package db
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path"
|
||||
|
||||
"github.com/alist-org/alist/v3/internal/model"
|
||||
"github.com/alist-org/alist/v3/pkg/utils"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
@ -15,10 +17,17 @@ func BatchCreateSearchNodes(nodes *[]model.SearchNode) error {
|
||||
return db.CreateInBatches(nodes, 1000).Error
|
||||
}
|
||||
|
||||
func DeleteSearchNodesByParent(parent string) error {
|
||||
return db.Where(fmt.Sprintf("%s LIKE ?",
|
||||
columnName("path")), fmt.Sprintf("%s%%", parent)).
|
||||
func DeleteSearchNodesByParent(prefix string) error {
|
||||
err := db.Where(fmt.Sprintf("%s LIKE ?",
|
||||
columnName("parent")), fmt.Sprintf("%s%%", prefix)).
|
||||
Delete(&model.SearchNode{}).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
dir, name := path.Split(prefix)
|
||||
return db.Where(fmt.Sprintf("%s = ? AND %s = ?",
|
||||
columnName("parent"), columnName("name")),
|
||||
utils.StandardizePath(dir), name).Delete(&model.SearchNode{}).Error
|
||||
}
|
||||
|
||||
func ClearSearchNodes() error {
|
||||
|
@ -59,11 +59,11 @@ func List(ctx context.Context, storage driver.Driver, path string, args model.Li
|
||||
return nil, errors.Wrapf(err, "failed to list objs")
|
||||
}
|
||||
// call hooks
|
||||
go func() {
|
||||
go func(reqPath string, files []model.Obj) {
|
||||
for _, hook := range objsUpdateHooks {
|
||||
hook(args.ReqPath, files)
|
||||
}
|
||||
}()
|
||||
}(args.ReqPath, files)
|
||||
if !storage.Config().NoCache {
|
||||
if len(files) > 0 {
|
||||
log.Debugf("set cache: %s => %+v", key, files)
|
||||
|
@ -187,6 +187,7 @@ func Update(parent string, objs []model.Obj) {
|
||||
toAdd := now.Difference(old)
|
||||
for i := range nodes {
|
||||
if toDelete.Contains(nodes[i].Name) {
|
||||
log.Debugf("delete index: %s", path.Join(parent, nodes[i].Name))
|
||||
err = instance.Del(ctx, path.Join(parent, nodes[i].Name))
|
||||
if err != nil {
|
||||
log.Errorf("update search index error while del old node: %+v", err)
|
||||
@ -196,6 +197,7 @@ func Update(parent string, objs []model.Obj) {
|
||||
}
|
||||
for i := range objs {
|
||||
if toAdd.Contains(objs[i].GetName()) {
|
||||
log.Debugf("add index: %s", path.Join(parent, objs[i].GetName()))
|
||||
err = Index(ctx, parent, objs[i])
|
||||
if err != nil {
|
||||
log.Errorf("update search index error while index new node: %+v", err)
|
||||
|
Loading…
x
Reference in New Issue
Block a user