7
7
"errors"
8
8
"fmt"
9
9
"io"
10
+ "slices"
10
11
11
12
coreclient "github.com/nspcc-dev/neofs-node/pkg/core/client"
12
13
"github.com/nspcc-dev/neofs-sdk-go/bearer"
@@ -415,8 +416,8 @@ func PutObject(prm PutObjectPrm) (*PutObjectRes, error) {
415
416
type SearchObjectsPrm struct {
416
417
readPrmCommon
417
418
418
- cid cid.ID
419
- cliPrm client. PrmObjectSearch
419
+ cid cid.ID
420
+ fs object. SearchFilters
420
421
}
421
422
422
423
// SetContainerID sets identifier of the container to search the objects.
@@ -428,53 +429,43 @@ func (x *SearchObjectsPrm) SetContainerID(id cid.ID) {
428
429
429
430
// SetFilters sets search filters.
430
431
func (x * SearchObjectsPrm ) SetFilters (fs object.SearchFilters ) {
431
- x .cliPrm .SetFilters (fs )
432
- }
433
-
434
- // SearchObjectsRes groups the resulting values of SearchObjects operation.
435
- type SearchObjectsRes struct {
436
- ids []oid.ID
437
- }
438
-
439
- // IDList returns identifiers of the matched objects.
440
- func (x SearchObjectsRes ) IDList () []oid.ID {
441
- return x .ids
432
+ x .fs = fs
442
433
}
443
434
444
435
// SearchObjects selects objects from container which match the filters.
445
436
//
446
437
// Returns any error which prevented the operation from completing correctly in error return.
447
- func SearchObjects (prm SearchObjectsPrm ) (* SearchObjectsRes , error ) {
438
+ func SearchObjects (prm SearchObjectsPrm ) ([]oid.ID , error ) {
439
+ var opts client.SearchObjectsOptions
448
440
if prm .local {
449
- prm . cliPrm . MarkLocal ()
441
+ opts . DisableForwarding ()
450
442
}
451
443
452
444
if prm .tokenSession != nil {
453
- prm . cliPrm . WithinSession (* prm .tokenSession )
445
+ opts . WithSessionToken (* prm .tokenSession )
454
446
}
455
447
456
448
if prm .tokenBearer != nil {
457
- prm .cliPrm .WithBearerToken (* prm .tokenBearer )
458
- }
459
-
460
- prm .cliPrm .WithXHeaders (prm .xHeaders ... )
461
-
462
- rdr , err := prm .cli .ObjectSearchInit (prm .ctx , prm .cid , prm .signer , prm .cliPrm )
463
- if err != nil {
464
- return nil , fmt .Errorf ("init object searching in client: %w" , err )
449
+ opts .WithBearerToken (* prm .tokenBearer )
465
450
}
466
451
467
- var ids []oid.ID
468
-
469
- err = rdr .Iterate (func (id oid.ID ) bool {
470
- ids = append (ids , id )
471
- return false
472
- })
473
- if err != nil {
474
- return nil , fmt .Errorf ("search objects using NeoFS API: %w" , err )
452
+ opts .WithXHeaders (prm .xHeaders ... )
453
+
454
+ var cursor string
455
+ var next []client.SearchResultItem
456
+ var res []oid.ID
457
+ var err error
458
+ for {
459
+ next , cursor , err = prm .cli .SearchObjects (prm .ctx , prm .cid , prm .fs , nil , cursor , prm .signer , opts )
460
+ if err != nil {
461
+ return nil , fmt .Errorf ("search objects RPC: %w" , err )
462
+ }
463
+ res = slices .Grow (res , len (res )+ len (next ))
464
+ for i := range next {
465
+ res = append (res , next [i ].ID )
466
+ }
467
+ if cursor == "" {
468
+ return res , nil
469
+ }
475
470
}
476
-
477
- return & SearchObjectsRes {
478
- ids : ids ,
479
- }, nil
480
471
}
0 commit comments