Skip to content

Commit 8456571

Browse files
feat(clients): expose waitForTasks to batch helpers [skip-bc] (#4030) (generated) [skip ci]
Co-authored-by: Clément Vannicatte <[email protected]>
1 parent 7f5fe6b commit 8456571

File tree

6 files changed

+123
-18
lines changed

6 files changed

+123
-18
lines changed

clients/algoliasearch-client-java/algoliasearch/src/main/java/com/algolia/api/SearchClient.java

Lines changed: 63 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6516,7 +6516,23 @@ public <T> List<BatchResponse> saveObjects(String indexName, Iterable<T> objects
65166516
* the transporter requestOptions. (optional)
65176517
*/
65186518
public <T> List<BatchResponse> saveObjects(String indexName, Iterable<T> objects, RequestOptions requestOptions) {
6519-
return chunkedBatch(indexName, objects, Action.ADD_OBJECT, false, 1000, requestOptions);
6519+
return saveObjects(indexName, objects, false, requestOptions);
6520+
}
6521+
6522+
/**
6523+
* Helper: Saves the given array of objects in the given index. The `chunkedBatch` helper is used
6524+
* under the hood, which creates a `batch` requests with at most 1000 objects in it.
6525+
*
6526+
* @param indexName The `indexName` to replace `objects` in.
6527+
* @param objects The array of `objects` to store in the given Algolia `indexName`.
6528+
* @param waitForTasks - Whether or not we should wait until every `batch` tasks has been
6529+
* processed, this operation may slow the total execution time of this method but is more
6530+
* reliable.
6531+
* @param requestOptions The requestOptions to send along with the query, they will be merged with
6532+
* the transporter requestOptions. (optional)
6533+
*/
6534+
public <T> List<BatchResponse> saveObjects(String indexName, Iterable<T> objects, boolean waitForTasks, RequestOptions requestOptions) {
6535+
return chunkedBatch(indexName, objects, Action.ADD_OBJECT, waitForTasks, 1000, requestOptions);
65206536
}
65216537

65226538
/**
@@ -6527,7 +6543,7 @@ public <T> List<BatchResponse> saveObjects(String indexName, Iterable<T> objects
65276543
* @param objectIDs The array of `objectIDs` to delete from the `indexName`.
65286544
*/
65296545
public List<BatchResponse> deleteObjects(String indexName, List<String> objectIDs) {
6530-
return deleteObjects(indexName, objectIDs, null);
6546+
return deleteObjects(indexName, objectIDs, false, null);
65316547
}
65326548

65336549
/**
@@ -6540,6 +6556,22 @@ public List<BatchResponse> deleteObjects(String indexName, List<String> objectID
65406556
* the transporter requestOptions. (optional)
65416557
*/
65426558
public List<BatchResponse> deleteObjects(String indexName, List<String> objectIDs, RequestOptions requestOptions) {
6559+
return deleteObjects(indexName, objectIDs, false, null);
6560+
}
6561+
6562+
/**
6563+
* Helper: Deletes every records for the given objectIDs. The `chunkedBatch` helper is used under
6564+
* the hood, which creates a `batch` requests with at most 1000 objectIDs in it.
6565+
*
6566+
* @param indexName The `indexName` to delete `objectIDs` from.
6567+
* @param objectIDs The array of `objectIDs` to delete from the `indexName`.
6568+
* @param waitForTasks - Whether or not we should wait until every `batch` tasks has been
6569+
* processed, this operation may slow the total execution time of this method but is more
6570+
* reliable.
6571+
* @param requestOptions The requestOptions to send along with the query, they will be merged with
6572+
* the transporter requestOptions. (optional)
6573+
*/
6574+
public List<BatchResponse> deleteObjects(String indexName, List<String> objectIDs, boolean waitForTasks, RequestOptions requestOptions) {
65436575
List<Map<String, String>> objects = new ArrayList<>();
65446576

65456577
for (String id : objectIDs) {
@@ -6548,7 +6580,7 @@ public List<BatchResponse> deleteObjects(String indexName, List<String> objectID
65486580
objects.add(obj);
65496581
}
65506582

6551-
return chunkedBatch(indexName, objects, Action.DELETE_OBJECT, false, 1000, requestOptions);
6583+
return chunkedBatch(indexName, objects, Action.DELETE_OBJECT, waitForTasks, 1000, requestOptions);
65526584
}
65536585

65546586
/**
@@ -6562,7 +6594,29 @@ public List<BatchResponse> deleteObjects(String indexName, List<String> objectID
65626594
* will fail.
65636595
*/
65646596
public <T> List<BatchResponse> partialUpdateObjects(String indexName, Iterable<T> objects, boolean createIfNotExists) {
6565-
return partialUpdateObjects(indexName, objects, createIfNotExists, null);
6597+
return partialUpdateObjects(indexName, objects, createIfNotExists, false, null);
6598+
}
6599+
6600+
/**
6601+
* Helper: Replaces object content of all the given objects according to their respective
6602+
* `objectID` field. The `chunkedBatch` helper is used under the hood, which creates a `batch`
6603+
* requests with at most 1000 objects in it.
6604+
*
6605+
* @param indexName The `indexName` to update `objects` in.
6606+
* @param objects The array of `objects` to update in the given Algolia `indexName`.
6607+
* @param createIfNotExists To be provided if non-existing objects are passed, otherwise, the call
6608+
* will fail.
6609+
* @param waitForTasks - Whether or not we should wait until every `batch` tasks has been
6610+
* processed, this operation may slow the total execution time of this method but is more
6611+
* reliable.
6612+
*/
6613+
public <T> List<BatchResponse> partialUpdateObjects(
6614+
String indexName,
6615+
Iterable<T> objects,
6616+
boolean createIfNotExists,
6617+
boolean waitForTasks
6618+
) {
6619+
return partialUpdateObjects(indexName, objects, createIfNotExists, waitForTasks, null);
65666620
}
65676621

65686622
/**
@@ -6574,20 +6628,24 @@ public <T> List<BatchResponse> partialUpdateObjects(String indexName, Iterable<T
65746628
* @param objects The array of `objects` to update in the given Algolia `indexName`.
65756629
* @param createIfNotExists To be provided if non-existing objects are passed, otherwise, the call
65766630
* will fail.
6631+
* @param waitForTasks - Whether or not we should wait until every `batch` tasks has been
6632+
* processed, this operation may slow the total execution time of this method but is more
6633+
* reliable.
65776634
* @param requestOptions The requestOptions to send along with the query, they will be merged with
65786635
* the transporter requestOptions. (optional)
65796636
*/
65806637
public <T> List<BatchResponse> partialUpdateObjects(
65816638
String indexName,
65826639
Iterable<T> objects,
65836640
boolean createIfNotExists,
6641+
boolean waitForTasks,
65846642
RequestOptions requestOptions
65856643
) {
65866644
return chunkedBatch(
65876645
indexName,
65886646
objects,
65896647
createIfNotExists ? Action.PARTIAL_UPDATE_OBJECT : Action.PARTIAL_UPDATE_OBJECT_NO_CREATE,
6590-
false,
6648+
waitForTasks,
65916649
1000,
65926650
requestOptions
65936651
);

clients/algoliasearch-client-javascript/packages/client-search/model/clientMethodProps.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -824,21 +824,21 @@ export type SearchClientNodeHelpers = {
824824
getSecuredApiKeyRemainingValidity: (opts: GetSecuredApiKeyRemainingValidityOptions) => number;
825825
};
826826

827-
export type DeleteObjectsOptions = Pick<ChunkedBatchOptions, 'indexName'> & {
827+
export type DeleteObjectsOptions = Pick<ChunkedBatchOptions, 'indexName' | 'waitForTasks'> & {
828828
/**
829829
* The objectIDs to delete.
830830
*/
831831
objectIDs: string[];
832832
};
833833

834-
export type PartialUpdateObjectsOptions = Pick<ChunkedBatchOptions, 'indexName' | 'objects'> & {
834+
export type PartialUpdateObjectsOptions = Pick<ChunkedBatchOptions, 'indexName' | 'objects' | 'waitForTasks'> & {
835835
/**
836836
*To be provided if non-existing objects are passed, otherwise, the call will fail.
837837
*/
838838
createIfNotExists?: boolean;
839839
};
840840

841-
export type SaveObjectsOptions = Pick<ChunkedBatchOptions, 'indexName' | 'objects'>;
841+
export type SaveObjectsOptions = Pick<ChunkedBatchOptions, 'indexName' | 'objects' | 'waitForTasks'>;
842842

843843
export type ChunkedBatchOptions = ReplaceAllObjectsOptions & {
844844
/**

clients/algoliasearch-client-javascript/packages/client-search/src/searchClient.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -550,13 +550,14 @@ export function createSearchClient({
550550
* @param saveObjects - The `saveObjects` object.
551551
* @param saveObjects.indexName - The `indexName` to save `objects` in.
552552
* @param saveObjects.objects - The array of `objects` to store in the given Algolia `indexName`.
553+
* @param saveObjects.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.
553554
* @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `batch` method and merged with the transporter requestOptions.
554555
*/
555556
async saveObjects(
556-
{ indexName, objects }: SaveObjectsOptions,
557+
{ indexName, objects, waitForTasks }: SaveObjectsOptions,
557558
requestOptions?: RequestOptions,
558559
): Promise<BatchResponse[]> {
559-
return await this.chunkedBatch({ indexName, objects, action: 'addObject' }, requestOptions);
560+
return await this.chunkedBatch({ indexName, objects, action: 'addObject', waitForTasks }, requestOptions);
560561
},
561562

562563
/**
@@ -566,17 +567,19 @@ export function createSearchClient({
566567
* @param deleteObjects - The `deleteObjects` object.
567568
* @param deleteObjects.indexName - The `indexName` to delete `objectIDs` from.
568569
* @param deleteObjects.objectIDs - The objectIDs to delete.
570+
* @param deleteObjects.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.
569571
* @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `batch` method and merged with the transporter requestOptions.
570572
*/
571573
async deleteObjects(
572-
{ indexName, objectIDs }: DeleteObjectsOptions,
574+
{ indexName, objectIDs, waitForTasks }: DeleteObjectsOptions,
573575
requestOptions?: RequestOptions,
574576
): Promise<BatchResponse[]> {
575577
return await this.chunkedBatch(
576578
{
577579
indexName,
578580
objects: objectIDs.map((objectID) => ({ objectID })),
579581
action: 'deleteObject',
582+
waitForTasks,
580583
},
581584
requestOptions,
582585
);
@@ -590,17 +593,19 @@ export function createSearchClient({
590593
* @param partialUpdateObjects.indexName - The `indexName` to update `objects` in.
591594
* @param partialUpdateObjects.objects - The array of `objects` to update in the given Algolia `indexName`.
592595
* @param partialUpdateObjects.createIfNotExists - To be provided if non-existing objects are passed, otherwise, the call will fail..
596+
* @param partialUpdateObjects.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.
593597
* @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `getTask` method and merged with the transporter requestOptions.
594598
*/
595599
async partialUpdateObjects(
596-
{ indexName, objects, createIfNotExists }: PartialUpdateObjectsOptions,
600+
{ indexName, objects, createIfNotExists, waitForTasks }: PartialUpdateObjectsOptions,
597601
requestOptions?: RequestOptions,
598602
): Promise<BatchResponse[]> {
599603
return await this.chunkedBatch(
600604
{
601605
indexName,
602606
objects,
603607
action: createIfNotExists ? 'partialUpdateObject' : 'partialUpdateObjectNoCreate',
608+
waitForTasks,
604609
},
605610
requestOptions,
606611
);

clients/algoliasearch-client-python/algoliasearch/search/client.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,7 @@ async def save_objects(
491491
self,
492492
index_name: str,
493493
objects: List[Dict[str, Any]],
494+
wait_for_tasks: bool = False,
494495
request_options: Optional[Union[dict, RequestOptions]] = None,
495496
) -> List[BatchResponse]:
496497
"""
@@ -500,13 +501,15 @@ async def save_objects(
500501
index_name=index_name,
501502
objects=objects,
502503
action=Action.ADDOBJECT,
504+
wait_for_tasks=wait_for_tasks,
503505
request_options=request_options,
504506
)
505507

506508
async def delete_objects(
507509
self,
508510
index_name: str,
509511
object_ids: List[str],
512+
wait_for_tasks: bool = False,
510513
request_options: Optional[Union[dict, RequestOptions]] = None,
511514
) -> List[BatchResponse]:
512515
"""
@@ -516,6 +519,7 @@ async def delete_objects(
516519
index_name=index_name,
517520
objects=[{"objectID": id} for id in object_ids],
518521
action=Action.DELETEOBJECT,
522+
wait_for_tasks=wait_for_tasks,
519523
request_options=request_options,
520524
)
521525

@@ -524,6 +528,7 @@ async def partial_update_objects(
524528
index_name: str,
525529
objects: List[Dict[str, Any]],
526530
create_if_not_exists: bool = False,
531+
wait_for_tasks: bool = False,
527532
request_options: Optional[Union[dict, RequestOptions]] = None,
528533
) -> List[BatchResponse]:
529534
"""
@@ -535,6 +540,7 @@ async def partial_update_objects(
535540
action=Action.PARTIALUPDATEOBJECT
536541
if create_if_not_exists
537542
else Action.PARTIALUPDATEOBJECTNOCREATE,
543+
wait_for_tasks=wait_for_tasks,
538544
request_options=request_options,
539545
)
540546

@@ -5494,6 +5500,7 @@ def save_objects(
54945500
self,
54955501
index_name: str,
54965502
objects: List[Dict[str, Any]],
5503+
wait_for_tasks: bool = False,
54975504
request_options: Optional[Union[dict, RequestOptions]] = None,
54985505
) -> List[BatchResponse]:
54995506
"""
@@ -5503,13 +5510,15 @@ def save_objects(
55035510
index_name=index_name,
55045511
objects=objects,
55055512
action=Action.ADDOBJECT,
5513+
wait_for_tasks=wait_for_tasks,
55065514
request_options=request_options,
55075515
)
55085516

55095517
def delete_objects(
55105518
self,
55115519
index_name: str,
55125520
object_ids: List[str],
5521+
wait_for_tasks: bool = False,
55135522
request_options: Optional[Union[dict, RequestOptions]] = None,
55145523
) -> List[BatchResponse]:
55155524
"""
@@ -5519,6 +5528,7 @@ def delete_objects(
55195528
index_name=index_name,
55205529
objects=[{"objectID": id} for id in object_ids],
55215530
action=Action.DELETEOBJECT,
5531+
wait_for_tasks=wait_for_tasks,
55225532
request_options=request_options,
55235533
)
55245534

@@ -5527,6 +5537,7 @@ def partial_update_objects(
55275537
index_name: str,
55285538
objects: List[Dict[str, Any]],
55295539
create_if_not_exists: bool = False,
5540+
wait_for_tasks: bool = False,
55305541
request_options: Optional[Union[dict, RequestOptions]] = None,
55315542
) -> List[BatchResponse]:
55325543
"""
@@ -5538,6 +5549,7 @@ def partial_update_objects(
55385549
action=Action.PARTIALUPDATEOBJECT
55395550
if create_if_not_exists
55405551
else Action.PARTIALUPDATEOBJECTNOCREATE,
5552+
wait_for_tasks=wait_for_tasks,
55415553
request_options=request_options,
55425554
)
55435555

clients/algoliasearch-client-ruby/lib/algolia/api/search_client.rb

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3333,16 +3333,17 @@ def get_secured_api_key_remaining_validity(secured_api_key)
33333333
#
33343334
# @param index_name [String]: The `index_name` to save `objects` in.
33353335
# @param objects [Array]: The array of `objects` to store in the given Algolia `indexName`.
3336+
# @param wait_for_tasks [Boolean]: 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.
33363337
# @param request_options: The request options to send along with the query, they will be merged with the transporter base parameters (headers, query params, timeouts, etc.). (optional)
33373338
#
33383339
# @return [BatchResponse]
33393340
#
3340-
def save_objects(index_name, objects, request_options = {})
3341+
def save_objects(index_name, objects, wait_for_tasks = false, request_options = {})
33413342
chunked_batch(
33423343
index_name,
33433344
objects,
33443345
Search::Action::ADD_OBJECT,
3345-
false,
3346+
wait_for_tasks,
33463347
1000,
33473348
request_options
33483349
)
@@ -3352,16 +3353,17 @@ def save_objects(index_name, objects, request_options = {})
33523353
#
33533354
# @param index_name [String]: The `index_name` to delete `object_ids` from.
33543355
# @param object_ids [Array]: The object_ids to delete.
3356+
# @param wait_for_tasks [Boolean]: 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.
33553357
# @param request_options: The request options to send along with the query, they will be merged with the transporter base parameters (headers, query params, timeouts, etc.). (optional)
33563358
#
33573359
# @return [BatchResponse]
33583360
#
3359-
def delete_objects(index_name, object_ids, request_options = {})
3361+
def delete_objects(index_name, object_ids, wait_for_tasks = false, request_options = {})
33603362
chunked_batch(
33613363
index_name,
33623364
object_ids.map { |id| {"objectID" => id} },
33633365
Search::Action::DELETE_OBJECT,
3364-
false,
3366+
wait_for_tasks,
33653367
1000,
33663368
request_options
33673369
)
@@ -3372,16 +3374,17 @@ def delete_objects(index_name, object_ids, request_options = {})
33723374
# @param index_name [String]: The `index_name` to delete `object_ids` from.
33733375
# @param objects [Array]: The objects to partially update.
33743376
# @param create_if_not_exists [Boolean]: To be provided if non-existing objects are passed, otherwise, the call will fail.
3377+
# @param wait_for_tasks [Boolean] 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.
33753378
# @param request_options: The request options to send along with the query, they will be merged with the transporter base parameters (headers, query params, timeouts, etc.). (optional)
33763379
#
33773380
# @return [BatchResponse]
33783381
#
3379-
def partial_update_objects(index_name, objects, create_if_not_exists, request_options = {})
3382+
def partial_update_objects(index_name, objects, create_if_not_exists, wait_for_tasks = false, request_options = {})
33803383
chunked_batch(
33813384
index_name,
33823385
objects,
33833386
create_if_not_exists ? Search::Action::PARTIAL_UPDATE_OBJECT : Search::Action::PARTIAL_UPDATE_OBJECT_NO_CREATE,
3384-
false,
3387+
wait_for_tasks,
33853388
1000,
33863389
request_options
33873390
)

0 commit comments

Comments
 (0)