[#1] Return iterator from ListContainersAsync and SearchObjectsAsync
Signed-off-by: Ivan Pchelintsev <i.pchelintsev@yadro.com>
This commit is contained in:
parent
70ba87bc60
commit
8cacbcc8e9
3 changed files with 21 additions and 18 deletions
|
@ -5,7 +5,7 @@ namespace FrostFS.SDK.ClientV2.Interfaces;
|
|||
public interface IFrostFSClient
|
||||
{
|
||||
Task<ModelsV2.Container> GetContainerAsync(ContainerId containerId);
|
||||
Task<ContainerId[]> ListContainersAsync();
|
||||
IAsyncEnumerable<ContainerId> ListContainersAsync();
|
||||
Task<ContainerId> CreateContainerAsync(ModelsV2.Container container);
|
||||
Task DeleteContainerAsync(ContainerId containerId);
|
||||
Task<ObjectHeader> GetObjectHeadAsync(ContainerId containerId, ObjectId objectId);
|
||||
|
@ -13,5 +13,5 @@ public interface IFrostFSClient
|
|||
Task<ObjectId> PutObjectAsync(ObjectHeader header, Stream payload);
|
||||
Task<ObjectId> PutObjectAsync(ObjectHeader header, byte[] payload);
|
||||
Task DeleteObjectAsync(ContainerId containerId, ObjectId objectId);
|
||||
Task<ObjectId[]> SearchObjectAsync(ContainerId cid, params ObjectFilter[] filters);
|
||||
IAsyncEnumerable<ObjectId> SearchObjectsAsync(ContainerId cid, params ObjectFilter[] filters);
|
||||
}
|
|
@ -21,8 +21,7 @@ public partial class Client
|
|||
return response.Body.Container.ToModel();
|
||||
}
|
||||
|
||||
//TODO: Return iterator
|
||||
public async Task<ContainerId[]> ListContainersAsync()
|
||||
public async IAsyncEnumerable<ContainerId> ListContainersAsync()
|
||||
{
|
||||
var request = new ListRequest
|
||||
{
|
||||
|
@ -34,9 +33,10 @@ public partial class Client
|
|||
request.AddMetaHeader();
|
||||
request.Sign(_key);
|
||||
var response = await _containerServiceClient.ListAsync(request);
|
||||
return response.Body.ContainerIds.Select(
|
||||
cid => ContainerId.FromHash(cid.Value.ToByteArray())
|
||||
).ToArray();
|
||||
foreach (var cid in response.Body.ContainerIds)
|
||||
{
|
||||
yield return ContainerId.FromHash(cid.Value.ToByteArray());
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<ContainerId> CreateContainerAsync(ModelsV2.Container container)
|
||||
|
@ -55,6 +55,7 @@ public partial class Client
|
|||
request.AddMetaHeader();
|
||||
request.Sign(_key);
|
||||
var response = await _containerServiceClient.PutAsync(request);
|
||||
RequestVerifier.ProcessResponse(response);
|
||||
return ContainerId.FromHash(response.Body.ContainerId.Value.ToByteArray());
|
||||
}
|
||||
|
||||
|
|
|
@ -179,8 +179,7 @@ public partial class Client
|
|||
await _objectServiceClient.DeleteAsync(request);
|
||||
}
|
||||
|
||||
//TODO: Return iterator
|
||||
public async Task<ObjectId[]> SearchObjectAsync(ContainerId cid, params ObjectFilter[] filters)
|
||||
public async IAsyncEnumerable<ObjectId> SearchObjectsAsync(ContainerId cid, params ObjectFilter[] filters)
|
||||
{
|
||||
var request = new SearchRequest
|
||||
{
|
||||
|
@ -199,25 +198,28 @@ public partial class Client
|
|||
;
|
||||
request.AddMetaHeader();
|
||||
request.Sign(_key);
|
||||
var ids = await SearchObject(request);
|
||||
return ids.Select(oid => ObjectId.FromHash(oid.Value.ToByteArray())).ToArray();
|
||||
var objectsIds = SearchObjects(request);
|
||||
await foreach (var oid in objectsIds)
|
||||
{
|
||||
yield return ObjectId.FromHash(oid.Value.ToByteArray());
|
||||
}
|
||||
}
|
||||
|
||||
private async Task<List<ObjectID>> SearchObject(SearchRequest request)
|
||||
private async IAsyncEnumerable<ObjectID> SearchObjects(SearchRequest request)
|
||||
{
|
||||
var objectsIds = new List<ObjectID> { };
|
||||
using var stream = SearchObjectInit(request);
|
||||
using var stream = SearchObjectsInit(request);
|
||||
var ids = await stream.Read();
|
||||
while (ids is not null)
|
||||
{
|
||||
objectsIds.AddRange(ids);
|
||||
foreach (var oid in ids)
|
||||
{
|
||||
yield return oid;
|
||||
}
|
||||
ids = await stream.Read();
|
||||
}
|
||||
|
||||
return objectsIds;
|
||||
}
|
||||
|
||||
private SearchReader SearchObjectInit(SearchRequest initRequest)
|
||||
private SearchReader SearchObjectsInit(SearchRequest initRequest)
|
||||
{
|
||||
if (initRequest is null)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue