From a7ac30da9c47abe0e2fffa49de287e8849d570ed Mon Sep 17 00:00:00 2001
From: Airat Arifullin <a.arifullin@yadro.com>
Date: Wed, 12 Mar 2025 17:01:56 +0300
Subject: [PATCH] [#1642] tree: Refactor `getSortedSubTree`

* Reuse `item` as result for `forest.TreeSortedByFilename`
  invocation.

Signed-off-by: Airat Arifullin <a.arifullin@yadro.com>
---
 pkg/services/tree/service.go | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/pkg/services/tree/service.go b/pkg/services/tree/service.go
index 98c5626bd..eeffec08b 100644
--- a/pkg/services/tree/service.go
+++ b/pkg/services/tree/service.go
@@ -463,14 +463,13 @@ func getSortedSubTree(ctx context.Context, srv TreeService_GetSubTreeServer, cid
 				break
 			}
 
-			nodes, last, err := forest.TreeSortedByFilename(ctx, cid, b.GetTreeId(), item.parent, item.last, batchSize)
+			var err error
+			item.values, item.last, err = forest.TreeSortedByFilename(ctx, cid, b.GetTreeId(), item.parent, item.last, batchSize)
 			if err != nil {
 				return err
 			}
-			item.values = nodes
-			item.last = last
 
-			if len(nodes) == 0 {
+			if len(item.values) == 0 {
 				stack = stack[:len(stack)-1]
 				continue
 			}