bring parentid logic back

Signed-off-by: jkoberg <jkoberg@owncloud.com>
This commit is contained in:
jkoberg committed 2022-10-12 13:54:07 +02:00
1 parent 2716cc1a76
commit 7113d905e0
8 files changed
+54 -47

No files matched your search

+1
View File
@@ -25,6 +25,7 @@ include ../../.make/generate.mk
.PHONY: ci-go-generate
ci-go-generate: $(MOCKERY) # CI runs ci-node-generate automatically before this target
$(MOCKERY) --dir pkg/engine --output pkg/engine/mocks --case underscore --name Engine
.PHONY: ci-node-generate
ci-node-generate:
+14 -6
View File
@@ -167,6 +167,11 @@ func (b *Bleve) Search(_ context.Context, sir *searchService.SearchIndexRequest)
return nil, err
}
pID, err := storagespace.ParseID(getValue[string](hit.Fields, "ParentID"))
if err != nil {
return nil, err
}
match := &searchMessage.Match{
Score: float32(hit.Score),
Entity: &searchMessage.Entity{
@@ -176,6 +181,7 @@ func (b *Bleve) Search(_ context.Context, sir *searchService.SearchIndexRequest)
},
Id: resourceIDtoSearchID(rID),
Name: getValue[string](hit.Fields, "Name"),
ParentId: resourceIDtoSearchID(pID),
Size: uint64(getValue[float64](hit.Fields, "Size")),
Type: uint64(getValue[float64](hit.Fields, "Type")),
MimeType: getValue[string](hit.Fields, "MimeType"),
@@ -203,7 +209,7 @@ func (b *Bleve) Upsert(id string, r Resource) error {
}
// Move updates the resource location and all of its necessary fields.
func (b *Bleve) Move(id string, target string) error {
func (b *Bleve) Move(id string, parentid string, target string) error {
r, err := b.getResource(id)
if err != nil {
return err
@@ -214,6 +220,7 @@ func (b *Bleve) Move(id string, target string) error {
r, err = b.updateEntity(id, func(r *Resource) {
r.Path = newName
r.Name = path.Base(newName)
r.ParentID = parentid
})
if err != nil {
return err
@@ -283,11 +290,12 @@ func (b *Bleve) getResource(id string) (*Resource, error) {
fields := res.Hits[0].Fields
return &Resource{
ID: getValue[string](fields, "ID"),
RootID: getValue[string](fields, "RootID"),
Path: getValue[string](fields, "Path"),
Type: uint64(getValue[float64](fields, "Type")),
Deleted: getValue[bool](fields, "Deleted"),
ID: getValue[string](fields, "ID"),
RootID: getValue[string](fields, "RootID"),
Path: getValue[string](fields, "Path"),
ParentID: getValue[string](fields, "ParentID"),
Type: uint64(getValue[float64](fields, "Type")),
Deleted: getValue[bool](fields, "Deleted"),
Document: content.Document{
Name: getValue[string](fields, "Name"),
Size: uint64(getValue[float64](fields, "Size")),
+14 -12
View File
@@ -3,6 +3,7 @@ package engine_test
import (
"context"
"fmt"
"github.com/blevesearch/bleve/v2"
sprovider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
. "github.com/onsi/ginkgo/v2"
@@ -19,7 +20,7 @@ var _ = Describe("Bleve", func() {
idx bleve.Index
ctx context.Context
createEntity = func(id sprovider.ResourceId, doc content.Document) engine.Resource {
createEntity = func(id sprovider.ResourceId, parentOpaque string, doc content.Document) engine.Resource {
name := doc.Name
if name == "" {
@@ -29,6 +30,7 @@ var _ = Describe("Bleve", func() {
return engine.Resource{
ID: fmt.Sprintf("%s$%s!%s", id.StorageId, id.SpaceId, id.OpaqueId),
RootID: fmt.Sprintf("%s$%s!%s", id.StorageId, id.SpaceId, id.OpaqueId),
ParentID: fmt.Sprintf("%s$%s!%s", id.StorageId, id.SpaceId, parentOpaque),
Path: fmt.Sprintf("./%s", name),
Document: doc,
}
@@ -82,7 +84,7 @@ var _ = Describe("Bleve", func() {
SpaceId: "2",
OpaqueId: "3",
}
r := createEntity(rid, content.Document{Tags: []string{"foo", "bar"}})
r := createEntity(rid, "p", content.Document{Tags: []string{"foo", "bar"}})
err := eng.Upsert(r.ID, r)
Expect(err).ToNot(HaveOccurred())
@@ -102,7 +104,7 @@ var _ = Describe("Bleve", func() {
SpaceId: "2",
OpaqueId: "3",
}
r := createEntity(rid, content.Document{Name: "Foo oo.pdf"})
r := createEntity(rid, "p", content.Document{Name: "Foo oo.pdf"})
err := eng.Upsert(r.ID, r)
Expect(err).ToNot(HaveOccurred())
assertDocCount(rid, `Name:foo o*`, 1)
@@ -114,7 +116,7 @@ var _ = Describe("Bleve", func() {
SpaceId: "2",
OpaqueId: "3",
}
r := createEntity(rid, content.Document{Name: "12345.pdf"})
r := createEntity(rid, "p", content.Document{Name: "12345.pdf"})
err := eng.Upsert(r.ID, r)
Expect(err).ToNot(HaveOccurred())
@@ -128,7 +130,7 @@ var _ = Describe("Bleve", func() {
SpaceId: "2",
OpaqueId: "3",
}
r := createEntity(rid, content.Document{Name: "foo.pdf"})
r := createEntity(rid, "p", content.Document{Name: "foo.pdf"})
err := eng.Upsert(r.ID, r)
Expect(err).ToNot(HaveOccurred())
@@ -147,7 +149,7 @@ var _ = Describe("Bleve", func() {
SpaceId: "2",
OpaqueId: "3",
}
r := createEntity(rid, content.Document{Name: "bar.pdf", Size: 789})
r := createEntity(rid, "p", content.Document{Name: "bar.pdf", Size: 789})
err := eng.Upsert(r.ID, r)
Expect(err).ToNot(HaveOccurred())
@@ -161,7 +163,7 @@ var _ = Describe("Bleve", func() {
SpaceId: "2",
OpaqueId: "3",
}
r := createEntity(rid, content.Document{Name: "bar.pdf"})
r := createEntity(rid, "p", content.Document{Name: "bar.pdf"})
err := eng.Upsert(r.ID, r)
Expect(err).ToNot(HaveOccurred())
@@ -176,7 +178,7 @@ var _ = Describe("Bleve", func() {
SpaceId: "2",
OpaqueId: "3",
}
r := createEntity(rid, content.Document{Name: "bar.pdf"})
r := createEntity(rid, "p", content.Document{Name: "bar.pdf"})
r.Type = 3
r.MimeType = "application/pdf"
@@ -204,7 +206,7 @@ var _ = Describe("Bleve", func() {
OpaqueId: string(rune(i + 3)),
}
r := createEntity(rid, content.Document{Name: "foo.pdf"})
r := createEntity(rid, "p", content.Document{Name: "foo.pdf"})
r.Size = uint64(i + 250)
err := eng.Upsert(r.ID, r)
Expect(err).ToNot(HaveOccurred())
@@ -224,7 +226,7 @@ var _ = Describe("Bleve", func() {
SpaceId: "2",
OpaqueId: "3",
}
r := createEntity(rid, content.Document{Name: "foo.pdf"})
r := createEntity(rid, "p", content.Document{Name: "foo.pdf"})
r.Type = 3
r.MimeType = "application/pdf"
@@ -249,7 +251,7 @@ var _ = Describe("Bleve", func() {
SpaceId: "2",
OpaqueId: "3",
}
entT = createEntity(ridT, content.Document{Name: "top.pdf"})
entT = createEntity(ridT, "p", content.Document{Name: "top.pdf"})
Expect(eng.Upsert(entT.ID, entT)).ToNot(HaveOccurred())
ridD = sprovider.ResourceId{
@@ -257,7 +259,7 @@ var _ = Describe("Bleve", func() {
SpaceId: "2",
OpaqueId: "4",
}
entD = createEntity(ridD, content.Document{Name: "deep.pdf"})
entD = createEntity(ridD, "p", content.Document{Name: "deep.pdf"})
entD.Path = "./nested/deep.pdf"
Expect(eng.Upsert(entD.ID, entD)).ToNot(HaveOccurred())
})
+7 -6
View File
@@ -16,7 +16,7 @@ import (
type Engine interface {
Search(ctx context.Context, req *searchSearvice.SearchIndexRequest) (*searchSearvice.SearchIndexResponse, error)
Upsert(id string, r Resource) error
Move(id string, target string) error
Move(id string, parentid string, target string) error
Delete(id string) error
Restore(id string) error
Purge(id string) error
@@ -27,11 +27,12 @@ type Engine interface {
type Resource struct {
content.Document
ID string
RootID string
Path string
Type uint64
Deleted bool
ID string
RootID string
Path string
ParentID string
Type uint64
Deleted bool
}
func resourceIDtoSearchID(id storageProvider.ResourceId) *searchMessage.ResourceID {
@@ -1,4 +1,4 @@
// Code generated by mockery v2.14.0. DO NOT EDIT.
// Code generated by mockery v2.10.4. DO NOT EDIT.
package mocks
@@ -51,13 +51,13 @@ func (_m *Engine) DocCount() (uint64, error) {
return r0, r1
}
// Move provides a mock function with given fields: id, target
func (_m *Engine) Move(id string, target string) error {
ret := _m.Called(id, target)
// Move provides a mock function with given fields: id, parentid, target
func (_m *Engine) Move(id string, parentid string, target string) error {
ret := _m.Called(id, parentid, target)
var r0 error
if rf, ok := ret.Get(0).(func(string, string) error); ok {
r0 = rf(id, target)
if rf, ok := ret.Get(0).(func(string, string, string) error); ok {
r0 = rf(id, parentid, target)
} else {
r0 = ret.Error(0)
}
@@ -129,18 +129,3 @@ func (_m *Engine) Upsert(id string, r engine.Resource) error {
return r0
}
type mockConstructorTestingTNewEngine interface {
mock.TestingT
Cleanup(func())
}
// NewEngine creates a new instance of Engine. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
func NewEngine(t mockConstructorTestingTNewEngine) *Engine {
mock := &Engine{}
mock.Mock.Test(t)
t.Cleanup(func() { mock.AssertExpectations(t) })
return mock
}
+2 -1
View File
@@ -115,6 +115,7 @@ func (eh *eventHandler) upsertItem(ref *provider.Reference, uid *user.UserId) {
OpaqueId: stat.Info.Id.SpaceId,
SpaceId: stat.Info.Id.SpaceId,
}),
ParentID: storagespace.FormatResourceID(*stat.GetInfo().GetParentId()),
Path: utils.MakeRelativePath(path),
Type: uint64(stat.Info.Type),
Document: doc,
@@ -144,7 +145,7 @@ func (eh *eventHandler) moveItem(ref *provider.Reference, uid *user.UserId) {
return
}
if err := eh.engine.Move(storagespace.FormatResourceID(*stat.Info.Id), path); err != nil {
if err := eh.engine.Move(storagespace.FormatResourceID(*stat.GetInfo().GetId()), storagespace.FormatResourceID(*stat.GetInfo().GetParentId()), path); err != nil {
eh.logger.Error().Err(err).Msg("failed to move the changed resource in the index")
}
}
+6 -1
View File
@@ -2,6 +2,7 @@ package search_test
import (
"context"
gateway "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1"
userv1beta1 "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
@@ -47,6 +48,10 @@ var _ = Describe("Events", func() {
StorageId: "storageid",
OpaqueId: "opaqueid",
},
ParentId: &provider.ResourceId{
StorageId: "storageid",
OpaqueId: "parentopaqueid",
},
Path: "foo.pdf",
Size: 12345,
}
@@ -164,7 +169,7 @@ var _ = Describe("Events", func() {
It("indexes items when they are being moved", func() {
called := false
engine.On("Move", mock.Anything, mock.Anything).Return(nil).Run(func(args mock.Arguments) {
engine.On("Move", mock.Anything, mock.Anything, mock.Anything).Return(nil).Run(func(args mock.Arguments) {
called = true
})
@@ -58,6 +58,10 @@ var _ = Describe("Searchprovider", func() {
StorageId: "storageid",
OpaqueId: "opaqueid",
},
ParentId: &sprovider.ResourceId{
StorageId: "storageid",
OpaqueId: "parentopaqueid",
},
Path: "foo.pdf",
Size: 12345,
}