Skip to content

Commit d849ff1

Browse files
authored
Merge ba1a018 into 3b61cf7
2 parents 3b61cf7 + ba1a018 commit d849ff1

File tree

13 files changed

+173
-51
lines changed

13 files changed

+173
-51
lines changed

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

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -167,24 +167,26 @@ public partial interface ISearchClient
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>
169169
/// <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>
170+
/// <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>
170171
/// <param name="options">Add extra http header or query parameters to Algolia.</param>
171172
/// <param name="cancellationToken">Cancellation Token to cancel the request.</param>
172173
/// <typeparam name="T"></typeparam>
173-
Task<List<BatchResponse>> SaveObjectsAsync<T>(string indexName, IEnumerable<T> objects, bool waitForTasks = false, RequestOptions options = null, CancellationToken cancellationToken = default) where T : class;
174+
Task<List<BatchResponse>> SaveObjectsAsync<T>(string indexName, IEnumerable<T> objects, bool waitForTasks = false, int batchSize = 1000, RequestOptions options = null, CancellationToken cancellationToken = default) where T : class;
174175
/// <inheritdoc cref="SaveObjectsAsync{T}(string, IEnumerable{T}, RequestOptions, CancellationToken)"/>
175-
List<BatchResponse> SaveObjects<T>(string indexName, IEnumerable<T> objects, bool waitForTasks = false, RequestOptions options = null, CancellationToken cancellationToken = default) where T : class;
176+
List<BatchResponse> SaveObjects<T>(string indexName, IEnumerable<T> objects, bool waitForTasks = false, int batchSize = 1000, RequestOptions options = null, CancellationToken cancellationToken = default) where T : class;
176177

177178
/// <summary>
178179
/// 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.
179180
/// </summary>
180181
/// <param name="indexName">The index in which to perform the request.</param>
181182
/// <param name="objectIDs">The list of `objectIDs` to remove from the given Algolia `indexName`.</param>
182183
/// <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>
184+
/// <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>
183185
/// <param name="options">Add extra http header or query parameters to Algolia.</param>
184186
/// <param name="cancellationToken">Cancellation Token to cancel the request.</param>
185-
Task<List<BatchResponse>> DeleteObjectsAsync(string indexName, IEnumerable<String> objectIDs, bool waitForTasks = false, RequestOptions options = null, CancellationToken cancellationToken = default);
187+
Task<List<BatchResponse>> DeleteObjectsAsync(string indexName, IEnumerable<String> objectIDs, bool waitForTasks = false, int batchSize = 1000, RequestOptions options = null, CancellationToken cancellationToken = default);
186188
/// <inheritdoc cref="DeleteObjectsAsync(string, IEnumerable{String}, RequestOptions, CancellationToken)"/>
187-
List<BatchResponse> DeleteObjects(string indexName, IEnumerable<String> objectIDs, bool waitForTasks = false, RequestOptions options = null, CancellationToken cancellationToken = default);
189+
List<BatchResponse> DeleteObjects(string indexName, IEnumerable<String> objectIDs, bool waitForTasks = false, int batchSize = 1000, RequestOptions options = null, CancellationToken cancellationToken = default);
188190

189191
/// <summary>
190192
/// 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.
@@ -193,11 +195,12 @@ public partial interface ISearchClient
193195
/// <param name="objects">The list of `objects` to update in the given Algolia `indexName`.</param>
194196
/// <param name="createIfNotExists">To be provided if non-existing objects are passed, otherwise, the call will fail.</param>
195197
/// <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>
198+
/// <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>
196199
/// <param name="options">Add extra http header or query parameters to Algolia.</param>
197200
/// <param name="cancellationToken">Cancellation Token to cancel the request.</param>
198-
Task<List<BatchResponse>> PartialUpdateObjectsAsync<T>(string indexName, IEnumerable<T> objects, bool createIfNotExists, bool waitForTasks = false, RequestOptions options = null, CancellationToken cancellationToken = default) where T : class;
201+
Task<List<BatchResponse>> PartialUpdateObjectsAsync<T>(string indexName, IEnumerable<T> objects, bool createIfNotExists, bool waitForTasks = false, int batchSize = 1000, RequestOptions options = null, CancellationToken cancellationToken = default) where T : class;
199202
/// <inheritdoc cref="PartialUpdateObjectsAsync{T}(string, IEnumerable{T}, bool, RequestOptions, CancellationToken)"/>
200-
List<BatchResponse> PartialUpdateObjects<T>(string indexName, IEnumerable<T> objects, bool createIfNotExists, bool waitForTasks = false, RequestOptions options = null, CancellationToken cancellationToken = default) where T : class;
203+
List<BatchResponse> PartialUpdateObjects<T>(string indexName, IEnumerable<T> objects, bool createIfNotExists, bool waitForTasks = false, int batchSize = 1000, RequestOptions options = null, CancellationToken cancellationToken = default) where T : class;
201204

202205
/// <summary>
203206
/// Helper: Check if an index exists.
@@ -568,43 +571,45 @@ public List<BatchResponse> ChunkedBatch<T>(string indexName, IEnumerable<T> obje
568571
/// <inheritdoc/>
569572
public async Task<List<BatchResponse>> SaveObjectsAsync<T>(string indexName, IEnumerable<T> objects,
570573
bool waitForTasks = false,
574+
int batchSize = 1000,
571575
RequestOptions options = null,
572576
CancellationToken cancellationToken = default) where T : class
573577
{
574-
return await ChunkedBatchAsync(indexName, objects, Action.AddObject, waitForTasks, 1000, options, cancellationToken).ConfigureAwait(false);
578+
return await ChunkedBatchAsync(indexName, objects, Action.AddObject, waitForTasks, batchSize, options, cancellationToken).ConfigureAwait(false);
575579
}
576580

577581
/// <inheritdoc/>
578-
public List<BatchResponse> SaveObjects<T>(string indexName, IEnumerable<T> objects, bool waitForTasks = false, RequestOptions options = null,
582+
public List<BatchResponse> SaveObjects<T>(string indexName, IEnumerable<T> objects, bool waitForTasks = false, int batchSize = 1000, RequestOptions options = null,
579583
CancellationToken cancellationToken = default) where T : class =>
580-
AsyncHelper.RunSync(() => SaveObjectsAsync(indexName, objects, waitForTasks, options, cancellationToken));
584+
AsyncHelper.RunSync(() => SaveObjectsAsync(indexName, objects, waitForTasks, batchSize, options, cancellationToken));
581585

582586
/// <inheritdoc/>
583587
public async Task<List<BatchResponse>> DeleteObjectsAsync(string indexName, IEnumerable<String> objectIDs,
584588
bool waitForTasks = false,
589+
int batchSize = 1000,
585590
RequestOptions options = null,
586591
CancellationToken cancellationToken = default)
587592
{
588-
return await ChunkedBatchAsync(indexName, objectIDs.Select(id => new { objectID = id }), Action.DeleteObject, waitForTasks, 1000, options, cancellationToken).ConfigureAwait(false);
593+
return await ChunkedBatchAsync(indexName, objectIDs.Select(id => new { objectID = id }), Action.DeleteObject, waitForTasks, batchSize, options, cancellationToken).ConfigureAwait(false);
589594
}
590595

591596
/// <inheritdoc/>
592-
public List<BatchResponse> DeleteObjects(string indexName, IEnumerable<String> objectIDs, bool waitForTasks = false, RequestOptions options = null,
597+
public List<BatchResponse> DeleteObjects(string indexName, IEnumerable<String> objectIDs, bool waitForTasks = false, int batchSize = 1000, RequestOptions options = null,
593598
CancellationToken cancellationToken = default) =>
594-
AsyncHelper.RunSync(() => DeleteObjectsAsync(indexName, objectIDs, waitForTasks, options, cancellationToken));
599+
AsyncHelper.RunSync(() => DeleteObjectsAsync(indexName, objectIDs, waitForTasks, batchSize, options, cancellationToken));
595600

596601
/// <inheritdoc/>
597-
public async Task<List<BatchResponse>> PartialUpdateObjectsAsync<T>(string indexName, IEnumerable<T> objects, bool createIfNotExists, bool waitForTasks = false,
602+
public async Task<List<BatchResponse>> PartialUpdateObjectsAsync<T>(string indexName, IEnumerable<T> objects, bool createIfNotExists, bool waitForTasks = false, int batchSize = 1000,
598603
RequestOptions options = null,
599604
CancellationToken cancellationToken = default) where T : class
600605
{
601-
return await ChunkedBatchAsync(indexName, objects, createIfNotExists ? Action.PartialUpdateObject : Action.PartialUpdateObjectNoCreate, waitForTasks, 1000, options, cancellationToken).ConfigureAwait(false);
606+
return await ChunkedBatchAsync(indexName, objects, createIfNotExists ? Action.PartialUpdateObject : Action.PartialUpdateObjectNoCreate, waitForTasks, batchSize, options, cancellationToken).ConfigureAwait(false);
602607
}
603608

604609
/// <inheritdoc/>
605-
public List<BatchResponse> PartialUpdateObjects<T>(string indexName, IEnumerable<T> objects, bool createIfNotExists, bool waitForTasks = false,
610+
public List<BatchResponse> PartialUpdateObjects<T>(string indexName, IEnumerable<T> objects, bool createIfNotExists, bool waitForTasks = false, int batchSize = 1000,
606611
RequestOptions options = null, CancellationToken cancellationToken = default) where T : class =>
607-
AsyncHelper.RunSync(() => PartialUpdateObjectsAsync(indexName, objects, createIfNotExists, waitForTasks, options, cancellationToken));
612+
AsyncHelper.RunSync(() => PartialUpdateObjectsAsync(indexName, objects, createIfNotExists, waitForTasks, batchSize, options, cancellationToken));
608613

609614
private static async Task<List<TU>> CreateIterable<TU>(Func<TU, Task<TU>> executeQuery,
610615
Func<TU, bool> stopCondition)

clients/algoliasearch-client-kotlin/client/src/commonMain/kotlin/com/algolia/client/extensions/SearchClient.kt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,7 @@ public suspend fun SearchClient.chunkedBatch(
371371
* @param indexName The index in which to perform the request.
372372
* @param objects The list of objects to index.
373373
* @param waitForTask If true, wait for the task to complete.
374+
* @param batchSize The size of the batch. Default is 1000.
374375
* @param requestOptions The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
375376
* @return The list of responses from the batch requests.
376377
*
@@ -379,14 +380,15 @@ public suspend fun SearchClient.saveObjects(
379380
indexName: String,
380381
objects: List<JsonObject>,
381382
waitForTask: Boolean = false,
383+
batchSize: Int = 1000,
382384
requestOptions: RequestOptions? = null,
383385
): List<BatchResponse> {
384386
return this.chunkedBatch(
385387
indexName = indexName,
386388
objects = objects,
387389
action = Action.AddObject,
388390
waitForTask = waitForTask,
389-
batchSize = 1000,
391+
batchSize = batchSize,
390392
requestOptions = requestOptions,
391393
)
392394
}
@@ -397,6 +399,7 @@ public suspend fun SearchClient.saveObjects(
397399
* @param indexName The index in which to perform the request.
398400
* @param objectIDs The list of objectIDs to delete from the index.
399401
* @param waitForTask If true, wait for the task to complete.
402+
* @param batchSize The size of the batch. Default is 1000.
400403
* @param requestOptions The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
401404
* @return The list of responses from the batch requests.
402405
*
@@ -405,14 +408,15 @@ public suspend fun SearchClient.deleteObjects(
405408
indexName: String,
406409
objectIDs: List<String>,
407410
waitForTask: Boolean = false,
411+
batchSize: Int = 1000,
408412
requestOptions: RequestOptions? = null,
409413
): List<BatchResponse> {
410414
return this.chunkedBatch(
411415
indexName = indexName,
412416
objects = objectIDs.map { id -> JsonObject(mapOf("objectID" to Json.encodeToJsonElement(id))) },
413417
action = Action.DeleteObject,
414418
waitForTask = waitForTask,
415-
batchSize = 1000,
419+
batchSize = batchSize,
416420
requestOptions = requestOptions,
417421
)
418422
}
@@ -424,6 +428,7 @@ public suspend fun SearchClient.deleteObjects(
424428
* @param objects The list of objects to update in the index.
425429
* @param createIfNotExists To be provided if non-existing objects are passed, otherwise, the call will fail..
426430
* @param waitForTask If true, wait for the task to complete.
431+
* @param batchSize The size of the batch. Default is 1000.
427432
* @param requestOptions The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
428433
* @return The list of responses from the batch requests.
429434
*
@@ -433,14 +438,15 @@ public suspend fun SearchClient.partialUpdateObjects(
433438
objects: List<JsonObject>,
434439
createIfNotExists: Boolean,
435440
waitForTask: Boolean = false,
441+
batchSize: Int = 1000,
436442
requestOptions: RequestOptions? = null,
437443
): List<BatchResponse> {
438444
return this.chunkedBatch(
439445
indexName = indexName,
440446
objects = objects,
441447
action = if (createIfNotExists) Action.PartialUpdateObject else Action.PartialUpdateObjectNoCreate,
442448
waitForTask = waitForTask,
443-
batchSize = 1000,
449+
batchSize = batchSize,
444450
requestOptions = requestOptions,
445451
)
446452
}

clients/algoliasearch-client-scala/src/main/scala/algoliasearch/extension/package.scala

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,8 @@ package object extension {
254254
* The list of objects to save.
255255
* @param waitForTasks
256256
* Whether to wait for the tasks to complete.
257+
* @param batchSize
258+
* The size of the batch. Default is 1000.
257259
* @param requestOptions
258260
* Additional request configuration.
259261
* @return
@@ -263,9 +265,10 @@ package object extension {
263265
indexName: String,
264266
objects: Seq[Any],
265267
waitForTasks: Boolean = false,
268+
batchSize: Int = 1000,
266269
requestOptions: Option[RequestOptions] = None
267270
)(implicit ec: ExecutionContext): Future[Seq[BatchResponse]] = {
268-
chunkedBatch(indexName, objects, Action.AddObject, waitForTasks, 1000, requestOptions)
271+
chunkedBatch(indexName, objects, Action.AddObject, waitForTasks, batchSize, requestOptions)
269272
}
270273

271274
/** Helper: Deletes every objects for the given objectIDs. The `chunkedBatch` helper is used under the hood, which
@@ -277,6 +280,8 @@ package object extension {
277280
* The list of objectIDs to delete.
278281
* @param waitForTasks
279282
* Whether to wait for the tasks to complete.
283+
* @param batchSize
284+
* The size of the batch. Default is 1000.
280285
* @param requestOptions
281286
* Additional request configuration.
282287
* @return
@@ -286,14 +291,15 @@ package object extension {
286291
indexName: String,
287292
objectIDs: Seq[String],
288293
waitForTasks: Boolean = false,
294+
batchSize: Int = 1000,
289295
requestOptions: Option[RequestOptions] = None
290296
)(implicit ec: ExecutionContext): Future[Seq[BatchResponse]] = {
291297
chunkedBatch(
292298
indexName,
293299
objectIDs.map(id => new { val objectID: String = id }),
294300
Action.DeleteObject,
295301
waitForTasks,
296-
1000,
302+
batchSize,
297303
requestOptions
298304
)
299305
}
@@ -309,6 +315,8 @@ package object extension {
309315
* To be provided if non-existing objects are passed, otherwise, the call will fail.
310316
* @param waitForTasks
311317
* Whether to wait for the tasks to complete.
318+
* @param batchSize
319+
* The size of the batch. Default is 1000.
312320
* @param requestOptions
313321
* Additional request configuration.
314322
* @return
@@ -319,14 +327,15 @@ package object extension {
319327
objects: Seq[Any],
320328
createIfNotExists: Boolean = false,
321329
waitForTasks: Boolean = false,
330+
batchSize: Int = 1000,
322331
requestOptions: Option[RequestOptions] = None
323332
)(implicit ec: ExecutionContext): Future[Seq[BatchResponse]] = {
324333
chunkedBatch(
325334
indexName,
326335
objects,
327336
if (createIfNotExists) Action.PartialUpdateObject else Action.PartialUpdateObjectNoCreate,
328337
waitForTasks,
329-
1000,
338+
batchSize,
330339
requestOptions
331340
)
332341
}

clients/algoliasearch-client-swift/Sources/Search/Extra/SearchClientExtension.swift

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -468,20 +468,22 @@ public extension SearchClient {
468468
/// - parameter indexName: The name of the index where to save the objects
469469
/// - parameter objects: The new objects
470470
/// - parameter waitForTasks: If we should wait for the batch task to be finished before processing the next one
471+
/// - parameter batchSize: The maximum number of objects to include in a batch
471472
/// - parameter requestOptions: The request options
472473
/// - returns: [BatchResponse]
473474
func saveObjects(
474475
indexName: String,
475476
objects: [some Encodable],
476477
waitForTasks: Bool = false,
478+
batchSize: Int = 1000,
477479
requestOptions: RequestOptions? = nil
478480
) async throws -> [BatchResponse] {
479481
try await self.chunkedBatch(
480482
indexName: indexName,
481483
objects: objects,
482484
action: .addObject,
483485
waitForTasks: waitForTasks,
484-
batchSize: 1000,
486+
batchSize: batchSize,
485487
requestOptions: requestOptions
486488
)
487489
}
@@ -491,20 +493,22 @@ public extension SearchClient {
491493
/// - parameter indexName: The name of the index to delete objectIDs from
492494
/// - parameter objectIDs: The objectIDs to delete
493495
/// - parameter waitForTasks: If we should wait for the batch task to be finished before processing the next one
496+
/// - parameter batchSize: The maximum number of objects to include in a batch
494497
/// - parameter requestOptions: The request options
495498
/// - returns: [BatchResponse]
496499
func deleteObjects(
497500
indexName: String,
498501
objectIDs: [String],
499502
waitForTasks: Bool = false,
503+
batchSize: Int = 1000,
500504
requestOptions: RequestOptions? = nil
501505
) async throws -> [BatchResponse] {
502506
try await self.chunkedBatch(
503507
indexName: indexName,
504508
objects: objectIDs.map { AnyCodable(["objectID": $0]) },
505509
action: .deleteObject,
506510
waitForTasks: waitForTasks,
507-
batchSize: 1000,
511+
batchSize: batchSize,
508512
requestOptions: requestOptions
509513
)
510514
}
@@ -516,21 +520,23 @@ public extension SearchClient {
516520
/// - parameter createIfNotExists: To be provided if non-existing objects are passed, otherwise, the call will
517521
/// fail..
518522
/// - parameter waitForTasks: If we should wait for the batch task to be finished before processing the next one
523+
/// - parameter batchSize: The maximum number of objects to include in a batch
519524
/// - parameter requestOptions: The request options
520525
/// - returns: [BatchResponse]
521526
func partialUpdateObjects(
522527
indexName: String,
523528
objects: [some Encodable],
524529
createIfNotExists: Bool = false,
525530
waitForTasks: Bool = false,
531+
batchSize: Int = 1000,
526532
requestOptions: RequestOptions? = nil
527533
) async throws -> [BatchResponse] {
528534
try await self.chunkedBatch(
529535
indexName: indexName,
530536
objects: objects,
531537
action: createIfNotExists ? .partialUpdateObject : .partialUpdateObjectNoCreate,
532538
waitForTasks: waitForTasks,
533-
batchSize: 1000,
539+
batchSize: batchSize,
534540
requestOptions: requestOptions
535541
)
536542
}

specs/search/helpers/deleteObjects.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ method:
2828
required: false
2929
schema:
3030
type: boolean
31+
- in: query
32+
name: batchSize
33+
description: The size of the chunk of `objects`. The number of `batch` calls will be equal to `length(objects) / batchSize`. Defaults to 1000.
34+
required: false
35+
schema:
36+
type: integer
3137
- in: query
3238
name: requestOptions
3339
description: The request options to pass to the `batch` method.

0 commit comments

Comments
 (0)