From 53926d5cd0a02b3ae26c627fa6550d3ace1af845 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=8D=E6=8F=92=E7=94=B5?= <69096367+r27153733@users.noreply.github.com> Date: Tue, 20 Feb 2024 19:12:07 +0800 Subject: [PATCH] fix(search): duplicate folder on autoupdate (#6063 close #6062) * fix(search): the problem of not returning in time when index does not support auto update. * fix(search): the problem of duplicate indexing of folders. --- internal/search/build.go | 17 +++++++++-------- server/handles/index.go | 1 + 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/internal/search/build.go b/internal/search/build.go index a806d08fadb..1d3bfb7cd5d 100644 --- a/internal/search/build.go +++ b/internal/search/build.go @@ -211,14 +211,15 @@ 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) - return - } - // build index if it's a folder - if objs[i].IsDir() { + if !objs[i].IsDir() { + 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) + return + } + } else { + // build index if it's a folder dir := path.Join(parent, objs[i].GetName()) err = BuildIndex(ctx, []string{dir}, diff --git a/server/handles/index.go b/server/handles/index.go index 4e8babd209f..0fa1fa0e9bf 100644 --- a/server/handles/index.go +++ b/server/handles/index.go @@ -51,6 +51,7 @@ func UpdateIndex(c *gin.Context) { } if !search.Config(c).AutoUpdate { common.ErrorStrResp(c, "update is not supported for current index", 400) + return } go func() { ctx := context.Background()