[#165] Sort nodes in ServiceClientMemory
Some checks failed
/ DCO (pull_request) Successful in 1m22s
/ Builds (1.20) (pull_request) Successful in 1m52s
/ Builds (1.21) (pull_request) Successful in 1m17s
/ Vulncheck (pull_request) Successful in 1m51s
/ Lint (pull_request) Failing after 1m55s
/ Tests (1.20) (pull_request) Successful in 2m24s
/ Tests (1.21) (pull_request) Successful in 2m24s

Signed-off-by: Denis Kirillov <d.kirillov@yadro.com>
This commit is contained in:
Denis Kirillov 2024-02-02 16:53:12 +03:00
parent a74d498df2
commit c334adeb6d
2 changed files with 5 additions and 12 deletions

View file

@ -222,7 +222,7 @@ func TestListObjectsVersionsPaging(t *testing.T) {
bktName := "bucket-versioning-enabled" bktName := "bucket-versioning-enabled"
createTestBucket(hc, bktName) createTestBucket(hc, bktName)
n := 10 n := 12
var objects []string var objects []string
for i := 0; i < n; i++ { for i := 0; i < n; i++ {

View file

@ -147,7 +147,6 @@ func (t *memoryTree) createPathIfNotExist(parent *treeNodeMemory, path []string)
} }
t.idCounter++ t.idCounter++
parent.children = append(parent.children, node) parent.children = append(parent.children, node)
//sortNodes(parent.children)
} }
return t.createPathIfNotExist(node, path[1:]) return t.createPathIfNotExist(node, path[1:])
@ -224,6 +223,8 @@ func (c *ServiceClientMemory) GetSubTree(_ context.Context, bktInfo *data.Bucket
return nil, ErrNodeNotFound return nil, ErrNodeNotFound
} }
sortNode(tr.treeData)
node := tr.treeData.getNode(rootID) node := tr.treeData.getNode(rootID)
if node == nil { if node == nil {
return nil, ErrNodeNotFound return nil, ErrNodeNotFound
@ -266,6 +267,8 @@ func (c *ServiceClientMemory) GetSubTreeStream(_ context.Context, bktInfo *data.
return nil, ErrNodeNotFound return nil, ErrNodeNotFound
} }
sortNode(tr.treeData)
return &SubTreeStreamMemoryImpl{ return &SubTreeStreamMemoryImpl{
res: node.listNodes(nil, depth-1), res: node.listNodes(nil, depth-1),
offset: 0, offset: 0,
@ -375,7 +378,6 @@ func (c *ServiceClientMemory) AddNodeByPath(_ context.Context, bktInfo *data.Buc
} }
parentNode.children = append(parentNode.children, tn) parentNode.children = append(parentNode.children, tn)
//sortNodes(parentNode.children)
cnr.trees[treeID] = tr cnr.trees[treeID] = tr
return newID, nil return newID, nil
@ -406,20 +408,11 @@ func (c *ServiceClientMemory) MoveNode(_ context.Context, bktInfo *data.BucketIn
node.data.parentID = parentID node.data.parentID = parentID
newParent.children = append(newParent.children, node) newParent.children = append(newParent.children, node)
//sortNodes(newParent.children)
node.parent.removeChild(nodeID) node.parent.removeChild(nodeID)
return nil return nil
} }
func (c *ServiceClientMemory) Sort() {
for _, info := range c.containers {
for _, tree := range info.trees {
sortNode(tree.treeData)
}
}
}
func sortNode(node *treeNodeMemory) { func sortNode(node *treeNodeMemory) {
if node == nil { if node == nil {
return return