diff --git a/internal/op/storage.go b/internal/op/storage.go index b9cd7561..d982245f 100644 --- a/internal/op/storage.go +++ b/internal/op/storage.go @@ -25,6 +25,10 @@ func GetAllStorages() []driver.Driver { return storagesMap.Values() } +func HasStorage(mountPath string) bool { + return storagesMap.Has(mountPath) +} + func GetStorageByVirtualPath(virtualPath string) (driver.Driver, error) { storageDriver, ok := storagesMap.Load(virtualPath) if !ok { diff --git a/internal/search/build.go b/internal/search/build.go index d4f8d172..19c4a806 100644 --- a/internal/search/build.go +++ b/internal/search/build.go @@ -201,7 +201,7 @@ func Update(parent string, objs []model.Obj) { toDelete := old.Difference(now) toAdd := now.Difference(old) for i := range nodes { - if toDelete.Contains(nodes[i].Name) { + if toDelete.Contains(nodes[i].Name) && !op.HasStorage(path.Join(parent, 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 { diff --git a/internal/search/searcher/searcher.go b/internal/search/searcher/searcher.go index a6c34a0a..6b753931 100644 --- a/internal/search/searcher/searcher.go +++ b/internal/search/searcher/searcher.go @@ -18,7 +18,7 @@ type Searcher interface { Search(ctx context.Context, req model.SearchReq) ([]model.SearchNode, int64, error) // Index obj with parent Index(ctx context.Context, node model.SearchNode) error - // Index obj with parent in batches + // BatchIndex obj with parent BatchIndex(ctx context.Context, nodes []model.SearchNode) error // Get by parent Get(ctx context.Context, parent string) ([]model.SearchNode, error) diff --git a/pkg/generic_sync/map.go b/pkg/generic_sync/map.go index b963602c..96612f0c 100644 --- a/pkg/generic_sync/map.go +++ b/pkg/generic_sync/map.go @@ -125,6 +125,11 @@ func (m *MapOf[K, V]) Load(key K) (value V, ok bool) { return e.load() } +func (m *MapOf[K, V]) Has(key K) bool { + _, ok := m.Load(key) + return ok +} + func (e *entry[V]) load() (value V, ok bool) { p := atomic.LoadPointer(&e.p) if p == nil || p == expunged {