Skip to content

Commit 7b40aa4

Browse files
feat(clients): allow batch size on objects helper [skip-bc] (generated)
algolia/api-clients-automation#4172 Co-authored-by: algolia-bot <[email protected]> Co-authored-by: Clément Vannicatte <[email protected]>
1 parent cfac4cb commit 7b40aa4

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

packages/client-search/model/clientMethodProps.ts

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

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

834-
export type PartialUpdateObjectsOptions = Pick<ChunkedBatchOptions, 'indexName' | 'objects' | 'waitForTasks'> & {
834+
export type PartialUpdateObjectsOptions = Pick<
835+
ChunkedBatchOptions,
836+
'indexName' | 'objects' | 'waitForTasks' | 'batchSize'
837+
> & {
835838
/**
836839
*To be provided if non-existing objects are passed, otherwise, the call will fail.
837840
*/
838841
createIfNotExists?: boolean;
839842
};
840843

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

843846
export type ChunkedBatchOptions = ReplaceAllObjectsOptions & {
844847
/**

packages/client-search/src/searchClient.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -550,14 +550,18 @@ 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 chunkedBatch.batchSize - The size of the chunk of `objects`. The number of `batch` calls will be equal to `length(objects) / batchSize`. Defaults to 1000.
553554
* @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.
554555
* @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `batch` method and merged with the transporter requestOptions.
555556
*/
556557
async saveObjects(
557-
{ indexName, objects, waitForTasks }: SaveObjectsOptions,
558+
{ indexName, objects, waitForTasks, batchSize }: SaveObjectsOptions,
558559
requestOptions?: RequestOptions,
559560
): Promise<BatchResponse[]> {
560-
return await this.chunkedBatch({ indexName, objects, action: 'addObject', waitForTasks }, requestOptions);
561+
return await this.chunkedBatch(
562+
{ indexName, objects, action: 'addObject', waitForTasks, batchSize },
563+
requestOptions,
564+
);
561565
},
562566

563567
/**
@@ -567,11 +571,12 @@ export function createSearchClient({
567571
* @param deleteObjects - The `deleteObjects` object.
568572
* @param deleteObjects.indexName - The `indexName` to delete `objectIDs` from.
569573
* @param deleteObjects.objectIDs - The objectIDs to delete.
574+
* @param chunkedBatch.batchSize - The size of the chunk of `objects`. The number of `batch` calls will be equal to `length(objects) / batchSize`. Defaults to 1000.
570575
* @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.
571576
* @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `batch` method and merged with the transporter requestOptions.
572577
*/
573578
async deleteObjects(
574-
{ indexName, objectIDs, waitForTasks }: DeleteObjectsOptions,
579+
{ indexName, objectIDs, waitForTasks, batchSize }: DeleteObjectsOptions,
575580
requestOptions?: RequestOptions,
576581
): Promise<BatchResponse[]> {
577582
return await this.chunkedBatch(
@@ -580,6 +585,7 @@ export function createSearchClient({
580585
objects: objectIDs.map((objectID) => ({ objectID })),
581586
action: 'deleteObject',
582587
waitForTasks,
588+
batchSize,
583589
},
584590
requestOptions,
585591
);
@@ -593,18 +599,20 @@ export function createSearchClient({
593599
* @param partialUpdateObjects.indexName - The `indexName` to update `objects` in.
594600
* @param partialUpdateObjects.objects - The array of `objects` to update in the given Algolia `indexName`.
595601
* @param partialUpdateObjects.createIfNotExists - To be provided if non-existing objects are passed, otherwise, the call will fail..
602+
* @param chunkedBatch.batchSize - The size of the chunk of `objects`. The number of `batch` calls will be equal to `length(objects) / batchSize`. Defaults to 1000.
596603
* @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.
597604
* @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `getTask` method and merged with the transporter requestOptions.
598605
*/
599606
async partialUpdateObjects(
600-
{ indexName, objects, createIfNotExists, waitForTasks }: PartialUpdateObjectsOptions,
607+
{ indexName, objects, createIfNotExists, waitForTasks, batchSize }: PartialUpdateObjectsOptions,
601608
requestOptions?: RequestOptions,
602609
): Promise<BatchResponse[]> {
603610
return await this.chunkedBatch(
604611
{
605612
indexName,
606613
objects,
607614
action: createIfNotExists ? 'partialUpdateObject' : 'partialUpdateObjectNoCreate',
615+
batchSize,
608616
waitForTasks,
609617
},
610618
requestOptions,

0 commit comments

Comments
 (0)