Skip to content

Commit 6cba333

Browse files
algolia-botmillotp
andcommitted
chore: generated code for commit 07266f22. [skip ci]
algolia/api-clients-automation@07266f2 Co-authored-by: algolia-bot <[email protected]> Co-authored-by: Pierre Millot <[email protected]>
1 parent 44d0f83 commit 6cba333

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

algoliasearch/Utils/SearchClientExtensions.cs

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -445,18 +445,18 @@ public async Task<ReplaceAllObjectsResponse> ReplaceAllObjectsAsync<T>(string in
445445

446446
var copyResponse = await OperationIndexAsync(indexName,
447447
new OperationIndexParams(OperationType.Copy, tmpIndexName)
448-
{ Scope = [ScopeType.Rules, ScopeType.Settings, ScopeType.Synonyms] }, options, cancellationToken)
448+
{ Scope = [ScopeType.Settings, ScopeType.Rules, ScopeType.Synonyms] }, options, cancellationToken)
449449
.ConfigureAwait(false);
450450

451-
var batchResponse = await ChunkedBatchAsync(tmpIndexName, objects, Action.AddObject, batchSize,
451+
var batchResponse = await ChunkedBatchAsync(tmpIndexName, objects, Action.AddObject, true, batchSize,
452452
options, cancellationToken).ConfigureAwait(false);
453453

454454
await WaitForTaskAsync(tmpIndexName, copyResponse.TaskID, requestOptions: options, ct: cancellationToken)
455455
.ConfigureAwait(false);
456456

457457
copyResponse = await OperationIndexAsync(indexName,
458458
new OperationIndexParams(OperationType.Copy, tmpIndexName)
459-
{ Scope = [ScopeType.Rules, ScopeType.Settings, ScopeType.Synonyms] }, options, cancellationToken)
459+
{ Scope = [ScopeType.Settings, ScopeType.Rules, ScopeType.Synonyms] }, options, cancellationToken)
460460
.ConfigureAwait(false);
461461
await WaitForTaskAsync(tmpIndexName, copyResponse.TaskID, requestOptions: options, ct: cancellationToken)
462462
.ConfigureAwait(false);
@@ -487,9 +487,9 @@ await WaitForTaskAsync(tmpIndexName, moveResponse.TaskID, requestOptions: option
487487
/// <param name="cancellationToken">Cancellation Token to cancel the request.</param>
488488
/// <typeparam name="T"></typeparam>
489489
public List<BatchResponse> ChunkedBatch<T>(string indexName, IEnumerable<T> objects, Action action = Action.AddObject,
490-
int batchSize = 1000, RequestOptions options = null, CancellationToken cancellationToken = default)
490+
bool waitForTasks = false, int batchSize = 1000, RequestOptions options = null, CancellationToken cancellationToken = default)
491491
where T : class =>
492-
AsyncHelper.RunSync(() => ChunkedBatchAsync(indexName, objects, action, batchSize, options, cancellationToken));
492+
AsyncHelper.RunSync(() => ChunkedBatchAsync(indexName, objects, action, waitForTasks, batchSize, options, cancellationToken));
493493

494494
/// <summary>
495495
/// Helper: Chunks the given `objects` list in subset of 1000 elements max in order to make it fit in `batch` requests.
@@ -502,7 +502,7 @@ public List<BatchResponse> ChunkedBatch<T>(string indexName, IEnumerable<T> obje
502502
/// <param name="cancellationToken">Cancellation Token to cancel the request.</param>
503503
/// <typeparam name="T"></typeparam>
504504
public async Task<List<BatchResponse>> ChunkedBatchAsync<T>(string indexName, IEnumerable<T> objects,
505-
Action action = Action.AddObject, int batchSize = 1000, RequestOptions options = null,
505+
Action action = Action.AddObject, bool waitForTasks = false, int batchSize = 1000, RequestOptions options = null,
506506
CancellationToken cancellationToken = default) where T : class
507507
{
508508
var batchCount = (int)Math.Ceiling((double)objects.Count() / batchSize);
@@ -518,10 +518,13 @@ public async Task<List<BatchResponse>> ChunkedBatchAsync<T>(string indexName, IE
518518
responses.Add(batchResponse);
519519
}
520520

521-
foreach (var batch in responses)
521+
if (waitForTasks)
522522
{
523-
await WaitForTaskAsync(indexName, batch.TaskID, requestOptions: options, ct: cancellationToken)
524-
.ConfigureAwait(false);
523+
foreach (var batch in responses)
524+
{
525+
await WaitForTaskAsync(indexName, batch.TaskID, requestOptions: options, ct: cancellationToken)
526+
.ConfigureAwait(false);
527+
}
525528
}
526529

527530
return responses;
@@ -544,7 +547,7 @@ public async Task<List<BatchResponse>> SaveObjectsAsync<T>(string indexName, IEn
544547
RequestOptions options = null,
545548
CancellationToken cancellationToken = default) where T : class
546549
{
547-
return await ChunkedBatchAsync(indexName, objects, Action.AddObject, 1000, options, cancellationToken).ConfigureAwait(false);
550+
return await ChunkedBatchAsync(indexName, objects, Action.AddObject, false, 1000, options, cancellationToken).ConfigureAwait(false);
548551
}
549552

550553
/// <summary>
@@ -554,11 +557,11 @@ public async Task<List<BatchResponse>> SaveObjectsAsync<T>(string indexName, IEn
554557
/// <param name="objectIDs">The list of `objectIDs` to remove from the given Algolia `indexName`.</param>
555558
/// <param name="options">Add extra http header or query parameters to Algolia.</param>
556559
/// <param name="cancellationToken">Cancellation Token to cancel the request.</param>
557-
public async Task<List<BatchResponse>> DeleteObjects(string indexName, IEnumerable<String> objectIDs,
560+
public async Task<List<BatchResponse>> DeleteObjectsAsync(string indexName, IEnumerable<String> objectIDs,
558561
RequestOptions options = null,
559562
CancellationToken cancellationToken = default)
560563
{
561-
return await ChunkedBatchAsync(indexName, objectIDs.Select(id => new { objectID = id }), Action.DeleteObject, 1000, options, cancellationToken).ConfigureAwait(false);
564+
return await ChunkedBatchAsync(indexName, objectIDs.Select(id => new { objectID = id }), Action.DeleteObject, false, 1000, options, cancellationToken).ConfigureAwait(false);
562565
}
563566

564567
/// <summary>
@@ -569,11 +572,11 @@ public async Task<List<BatchResponse>> DeleteObjects(string indexName, IEnumerab
569572
/// <param name="createIfNotExists">To be provided if non-existing objects are passed, otherwise, the call will fail.</param>
570573
/// <param name="options">Add extra http header or query parameters to Algolia.</param>
571574
/// <param name="cancellationToken">Cancellation Token to cancel the request.</param>
572-
public async Task<List<BatchResponse>> PartialUpdateObjects<T>(string indexName, IEnumerable<T> objects, bool createIfNotExists,
575+
public async Task<List<BatchResponse>> PartialUpdateObjectsAsync<T>(string indexName, IEnumerable<T> objects, bool createIfNotExists,
573576
RequestOptions options = null,
574577
CancellationToken cancellationToken = default) where T : class
575578
{
576-
return await ChunkedBatchAsync(indexName, objects, createIfNotExists ? Action.PartialUpdateObject : Action.PartialUpdateObjectNoCreate, 1000, options, cancellationToken).ConfigureAwait(false);
579+
return await ChunkedBatchAsync(indexName, objects, createIfNotExists ? Action.PartialUpdateObject : Action.PartialUpdateObjectNoCreate, false, 1000, options, cancellationToken).ConfigureAwait(false);
577580
}
578581

579582
private static async Task<List<TU>> CreateIterable<TU>(Func<TU, Task<TU>> executeQuery,

0 commit comments

Comments
 (0)