Skip to content

Commit 0f81e4e

Browse files
committed
feat: csharp
1 parent 8e33ee0 commit 0f81e4e

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

clients/algoliasearch-client-csharp/algoliasearch/Utils/SearchClientExtensions.cs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -166,23 +166,25 @@ public partial interface ISearchClient
166166
/// </summary>
167167
/// <param name="indexName">The index in which to perform the request.</param>
168168
/// <param name="objects">The list of `objects` to store in the given Algolia `indexName`.</param>
169+
/// <param name="waitForTasks">Whether or not we should wait until every `batch` tasks has been processed, this operation may slow the total execution time of this method but is more reliable..</param>
169170
/// <param name="options">Add extra http header or query parameters to Algolia.</param>
170171
/// <param name="cancellationToken">Cancellation Token to cancel the request.</param>
171172
/// <typeparam name="T"></typeparam>
172-
Task<List<BatchResponse>> SaveObjectsAsync<T>(string indexName, IEnumerable<T> objects, RequestOptions options = null, CancellationToken cancellationToken = default) where T : class;
173+
Task<List<BatchResponse>> SaveObjectsAsync<T>(string indexName, IEnumerable<T> objects, bool waitForTasks = false, RequestOptions options = null, CancellationToken cancellationToken = default) where T : class;
173174
/// <inheritdoc cref="SaveObjectsAsync{T}(string, IEnumerable{T}, RequestOptions, CancellationToken)"/>
174-
List<BatchResponse> SaveObjects<T>(string indexName, IEnumerable<T> objects, RequestOptions options = null, CancellationToken cancellationToken = default) where T : class;
175+
List<BatchResponse> SaveObjects<T>(string indexName, IEnumerable<T> objects, bool waitForTasks = false, RequestOptions options = null, CancellationToken cancellationToken = default) where T : class;
175176

176177
/// <summary>
177178
/// Helper: Deletes every records for the given objectIDs. The `chunkedBatch` helper is used under the hood, which creates a `batch` requests with at most 1000 objectIDs in it.
178179
/// </summary>
179180
/// <param name="indexName">The index in which to perform the request.</param>
180181
/// <param name="objectIDs">The list of `objectIDs` to remove from the given Algolia `indexName`.</param>
182+
/// <param name="waitForTasks">Whether or not we should wait until every `batch` tasks has been processed, this operation may slow the total execution time of this method but is more reliable..</param>
181183
/// <param name="options">Add extra http header or query parameters to Algolia.</param>
182184
/// <param name="cancellationToken">Cancellation Token to cancel the request.</param>
183-
Task<List<BatchResponse>> DeleteObjectsAsync(string indexName, IEnumerable<String> objectIDs, RequestOptions options = null, CancellationToken cancellationToken = default);
185+
Task<List<BatchResponse>> DeleteObjectsAsync(string indexName, IEnumerable<String> objectIDs, bool waitForTasks = false, RequestOptions options = null, CancellationToken cancellationToken = default);
184186
/// <inheritdoc cref="DeleteObjectsAsync(string, IEnumerable{String}, RequestOptions, CancellationToken)"/>
185-
List<BatchResponse> DeleteObjects(string indexName, IEnumerable<String> objectIDs, RequestOptions options = null, CancellationToken cancellationToken = default);
187+
List<BatchResponse> DeleteObjects(string indexName, IEnumerable<String> objectIDs, bool waitForTasks = false, RequestOptions options = null, CancellationToken cancellationToken = default);
186188

187189
/// <summary>
188190
/// Helper: Replaces object content of all the given objects according to their respective `objectID` field. The `chunkedBatch` helper is used under the hood, which creates a `batch` requests with at most 1000 objects in it.
@@ -564,29 +566,31 @@ public List<BatchResponse> ChunkedBatch<T>(string indexName, IEnumerable<T> obje
564566

565567
/// <inheritdoc/>
566568
public async Task<List<BatchResponse>> SaveObjectsAsync<T>(string indexName, IEnumerable<T> objects,
569+
bool waitForTasks = false,
567570
RequestOptions options = null,
568571
CancellationToken cancellationToken = default) where T : class
569572
{
570-
return await ChunkedBatchAsync(indexName, objects, Action.AddObject, false, 1000, options, cancellationToken).ConfigureAwait(false);
573+
return await ChunkedBatchAsync(indexName, objects, Action.AddObject, waitForTasks, 1000, options, cancellationToken).ConfigureAwait(false);
571574
}
572575

573576
/// <inheritdoc/>
574-
public List<BatchResponse> SaveObjects<T>(string indexName, IEnumerable<T> objects, RequestOptions options = null,
577+
public List<BatchResponse> SaveObjects<T>(string indexName, IEnumerable<T> objects, bool waitForTasks = false, RequestOptions options = null,
575578
CancellationToken cancellationToken = default) where T : class =>
576-
AsyncHelper.RunSync(() => SaveObjectsAsync(indexName, objects, options, cancellationToken));
579+
AsyncHelper.RunSync(() => SaveObjectsAsync(indexName, objects, waitForTasks, options, cancellationToken));
577580

578581
/// <inheritdoc/>
579582
public async Task<List<BatchResponse>> DeleteObjectsAsync(string indexName, IEnumerable<String> objectIDs,
583+
bool waitForTasks = false,
580584
RequestOptions options = null,
581585
CancellationToken cancellationToken = default)
582586
{
583-
return await ChunkedBatchAsync(indexName, objectIDs.Select(id => new { objectID = id }), Action.DeleteObject, false, 1000, options, cancellationToken).ConfigureAwait(false);
587+
return await ChunkedBatchAsync(indexName, objectIDs.Select(id => new { objectID = id }), Action.DeleteObject, waitForTasks, 1000, options, cancellationToken).ConfigureAwait(false);
584588
}
585589

586590
/// <inheritdoc/>
587-
public List<BatchResponse> DeleteObjects(string indexName, IEnumerable<String> objectIDs, RequestOptions options = null,
591+
public List<BatchResponse> DeleteObjects(string indexName, IEnumerable<String> objectIDs, bool waitForTasks = false, RequestOptions options = null,
588592
CancellationToken cancellationToken = default) =>
589-
AsyncHelper.RunSync(() => DeleteObjectsAsync(indexName, objectIDs, options, cancellationToken));
593+
AsyncHelper.RunSync(() => DeleteObjectsAsync(indexName, objectIDs, waitForTasks, options, cancellationToken));
590594

591595
/// <inheritdoc/>
592596
public async Task<List<BatchResponse>> PartialUpdateObjectsAsync<T>(string indexName, IEnumerable<T> objects, bool createIfNotExists,

0 commit comments

Comments
 (0)