Skip to content

Commit f5cc2cb

Browse files
algolia-botmillotp
andcommitted
feat(clients): add optionnal scopes to replaceAllObjects [skip-bc] (generated)
algolia/api-clients-automation#4296 Co-authored-by: algolia-bot <[email protected]> Co-authored-by: Pierre Millot <[email protected]>
1 parent ae1f32e commit f5cc2cb

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

algoliasearch/Utils/SearchClientExtensions.cs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,12 @@ public partial interface ISearchClient
140140
/// <param name="indexName">The index in which to perform the request.</param>
141141
/// <param name="objects">The list of `objects` to store in the given Algolia `indexName`.</param>
142142
/// <param name="batchSize">The size of the chunk of `objects`. The number of `batch` calls will be equal to `length(objects) / batchSize`. Defaults to 1000.</param>
143+
/// <param name="scopes"> The `scopes` to keep from the index. Defaults to ['settings', 'rules', 'synonyms'].</param>
143144
/// <param name="options">Add extra http header or query parameters to Algolia.</param>
144145
/// <param name="cancellationToken">Cancellation Token to cancel the request.</param>
145-
Task<ReplaceAllObjectsResponse> ReplaceAllObjectsAsync<T>(string indexName, IEnumerable<T> objects, int batchSize = 1000, RequestOptions options = null, CancellationToken cancellationToken = default) where T : class;
146+
Task<ReplaceAllObjectsResponse> ReplaceAllObjectsAsync<T>(string indexName, IEnumerable<T> objects, int batchSize = 1000, List<ScopeType> scopes = null, RequestOptions options = null, CancellationToken cancellationToken = default) where T : class;
146147
/// <inheritdoc cref="ReplaceAllObjectsAsync{T}(string, IEnumerable{T}, int, RequestOptions, CancellationToken)"/>
147-
ReplaceAllObjectsResponse ReplaceAllObjects<T>(string indexName, IEnumerable<T> objects, int batchSize = 1000, RequestOptions options = null, CancellationToken cancellationToken = default) where T : class;
148+
ReplaceAllObjectsResponse ReplaceAllObjects<T>(string indexName, IEnumerable<T> objects, int batchSize = 1000, List<ScopeType> scopes = null, RequestOptions options = null, CancellationToken cancellationToken = default) where T : class;
148149

149150
/// <summary>
150151
/// Helper: Chunks the given `objects` list in subset of 1000 elements max in order to make it fit in `batch` requests.
@@ -484,21 +485,26 @@ private static int NextDelay(int retryCount)
484485

485486
/// <inheritdoc/>
486487
public async Task<ReplaceAllObjectsResponse> ReplaceAllObjectsAsync<T>(string indexName, IEnumerable<T> objects,
487-
int batchSize = 1000, RequestOptions options = null, CancellationToken cancellationToken = default) where T : class
488+
int batchSize = 1000, List<ScopeType> scopes = null, RequestOptions options = null, CancellationToken cancellationToken = default) where T : class
488489
{
489490
if (objects == null)
490491
{
491492
throw new ArgumentNullException(nameof(objects));
492493
}
493494

495+
if (scopes == null)
496+
{
497+
scopes = new List<ScopeType> { ScopeType.Settings, ScopeType.Rules, ScopeType.Synonyms };
498+
}
499+
494500
var rnd = new Random();
495501
var tmpIndexName = $"{indexName}_tmp_{rnd.Next(100)}";
496502

497503
try
498504
{
499505
var copyResponse = await OperationIndexAsync(indexName,
500506
new OperationIndexParams(OperationType.Copy, tmpIndexName)
501-
{ Scope = [ScopeType.Settings, ScopeType.Rules, ScopeType.Synonyms] }, options, cancellationToken)
507+
{ Scope = scopes }, options, cancellationToken)
502508
.ConfigureAwait(false);
503509

504510
var batchResponse = await ChunkedBatchAsync(tmpIndexName, objects, Action.AddObject, true, batchSize,
@@ -509,7 +515,7 @@ await WaitForTaskAsync(tmpIndexName, copyResponse.TaskID, requestOptions: option
509515

510516
copyResponse = await OperationIndexAsync(indexName,
511517
new OperationIndexParams(OperationType.Copy, tmpIndexName)
512-
{ Scope = [ScopeType.Settings, ScopeType.Rules, ScopeType.Synonyms] }, options, cancellationToken)
518+
{ Scope = scopes }, options, cancellationToken)
513519
.ConfigureAwait(false);
514520
await WaitForTaskAsync(tmpIndexName, copyResponse.TaskID, requestOptions: options, ct: cancellationToken)
515521
.ConfigureAwait(false);
@@ -537,9 +543,9 @@ await WaitForTaskAsync(tmpIndexName, moveResponse.TaskID, requestOptions: option
537543
}
538544

539545
/// <inheritdoc/>
540-
public ReplaceAllObjectsResponse ReplaceAllObjects<T>(string indexName, IEnumerable<T> objects, int batchSize = 1000,
546+
public ReplaceAllObjectsResponse ReplaceAllObjects<T>(string indexName, IEnumerable<T> objects, int batchSize = 1000, List<ScopeType> scopes = null,
541547
RequestOptions options = null, CancellationToken cancellationToken = default) where T : class =>
542-
AsyncHelper.RunSync(() => ReplaceAllObjectsAsync(indexName, objects, batchSize, options, cancellationToken));
548+
AsyncHelper.RunSync(() => ReplaceAllObjectsAsync(indexName, objects, batchSize, scopes, options, cancellationToken));
543549

544550
/// <inheritdoc/>
545551
public async Task<List<BatchResponse>> ChunkedBatchAsync<T>(string indexName, IEnumerable<T> objects,

0 commit comments

Comments
 (0)