From c334adeb6da0bf6fa889b1bf8bb370ccc80f2b0e Mon Sep 17 00:00:00 2001 From: Denis Kirillov Date: Fri, 2 Feb 2024 16:53:12 +0300 Subject: [PATCH] [#165] Sort nodes in ServiceClientMemory Signed-off-by: Denis Kirillov --- api/handler/object_list_test.go | 2 +- pkg/service/tree/tree_client_in_memory.go | 15 ++++----------- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/api/handler/object_list_test.go b/api/handler/object_list_test.go index 7b813e7..1a41086 100644 --- a/api/handler/object_list_test.go +++ b/api/handler/object_list_test.go @@ -222,7 +222,7 @@ func TestListObjectsVersionsPaging(t *testing.T) { bktName := "bucket-versioning-enabled" createTestBucket(hc, bktName) - n := 10 + n := 12 var objects []string for i := 0; i < n; i++ { diff --git a/pkg/service/tree/tree_client_in_memory.go b/pkg/service/tree/tree_client_in_memory.go index 1429c0b..f70c973 100644 --- a/pkg/service/tree/tree_client_in_memory.go +++ b/pkg/service/tree/tree_client_in_memory.go @@ -147,7 +147,6 @@ func (t *memoryTree) createPathIfNotExist(parent *treeNodeMemory, path []string) } t.idCounter++ parent.children = append(parent.children, node) - //sortNodes(parent.children) } return t.createPathIfNotExist(node, path[1:]) @@ -224,6 +223,8 @@ func (c *ServiceClientMemory) GetSubTree(_ context.Context, bktInfo *data.Bucket return nil, ErrNodeNotFound } + sortNode(tr.treeData) + node := tr.treeData.getNode(rootID) if node == nil { return nil, ErrNodeNotFound @@ -266,6 +267,8 @@ func (c *ServiceClientMemory) GetSubTreeStream(_ context.Context, bktInfo *data. return nil, ErrNodeNotFound } + sortNode(tr.treeData) + return &SubTreeStreamMemoryImpl{ res: node.listNodes(nil, depth-1), offset: 0, @@ -375,7 +378,6 @@ func (c *ServiceClientMemory) AddNodeByPath(_ context.Context, bktInfo *data.Buc } parentNode.children = append(parentNode.children, tn) - //sortNodes(parentNode.children) cnr.trees[treeID] = tr return newID, nil @@ -406,20 +408,11 @@ func (c *ServiceClientMemory) MoveNode(_ context.Context, bktInfo *data.BucketIn node.data.parentID = parentID newParent.children = append(newParent.children, node) - //sortNodes(newParent.children) node.parent.removeChild(nodeID) return nil } -func (c *ServiceClientMemory) Sort() { - for _, info := range c.containers { - for _, tree := range info.trees { - sortNode(tree.treeData) - } - } -} - func sortNode(node *treeNodeMemory) { if node == nil { return -- 2.45.2