Skip to content

Commit

Permalink
feat(clients): allow batch size on objects helper [skip-bc] (generated)
Browse files Browse the repository at this point in the history
algolia/api-clients-automation#4172

Co-authored-by: algolia-bot <[email protected]>
Co-authored-by: Clément Vannicatte <[email protected]>
  • Loading branch information
algolia-bot and shortcuts committed Nov 29, 2024
1 parent cfac4cb commit 7b40aa4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
9 changes: 6 additions & 3 deletions packages/client-search/model/clientMethodProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -824,21 +824,24 @@ export type SearchClientNodeHelpers = {
getSecuredApiKeyRemainingValidity: (opts: GetSecuredApiKeyRemainingValidityOptions) => number;
};

export type DeleteObjectsOptions = Pick<ChunkedBatchOptions, 'indexName' | 'waitForTasks'> & {
export type DeleteObjectsOptions = Pick<ChunkedBatchOptions, 'indexName' | 'waitForTasks' | 'batchSize'> & {
/**
* The objectIDs to delete.
*/
objectIDs: string[];
};

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

export type SaveObjectsOptions = Pick<ChunkedBatchOptions, 'indexName' | 'objects' | 'waitForTasks'>;
export type SaveObjectsOptions = Pick<ChunkedBatchOptions, 'indexName' | 'objects' | 'waitForTasks' | 'batchSize'>;

export type ChunkedBatchOptions = ReplaceAllObjectsOptions & {
/**
Expand Down
16 changes: 12 additions & 4 deletions packages/client-search/src/searchClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -550,14 +550,18 @@ export function createSearchClient({
* @param saveObjects - The `saveObjects` object.
* @param saveObjects.indexName - The `indexName` to save `objects` in.
* @param saveObjects.objects - The array of `objects` to store in the given Algolia `indexName`.
* @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.
* @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.
* @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `batch` method and merged with the transporter requestOptions.
*/
async saveObjects(
{ indexName, objects, waitForTasks }: SaveObjectsOptions,
{ indexName, objects, waitForTasks, batchSize }: SaveObjectsOptions,
requestOptions?: RequestOptions,
): Promise<BatchResponse[]> {
return await this.chunkedBatch({ indexName, objects, action: 'addObject', waitForTasks }, requestOptions);
return await this.chunkedBatch(
{ indexName, objects, action: 'addObject', waitForTasks, batchSize },
requestOptions,
);
},

/**
Expand All @@ -567,11 +571,12 @@ export function createSearchClient({
* @param deleteObjects - The `deleteObjects` object.
* @param deleteObjects.indexName - The `indexName` to delete `objectIDs` from.
* @param deleteObjects.objectIDs - The objectIDs to delete.
* @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.
* @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.
* @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `batch` method and merged with the transporter requestOptions.
*/
async deleteObjects(
{ indexName, objectIDs, waitForTasks }: DeleteObjectsOptions,
{ indexName, objectIDs, waitForTasks, batchSize }: DeleteObjectsOptions,
requestOptions?: RequestOptions,
): Promise<BatchResponse[]> {
return await this.chunkedBatch(
Expand All @@ -580,6 +585,7 @@ export function createSearchClient({
objects: objectIDs.map((objectID) => ({ objectID })),
action: 'deleteObject',
waitForTasks,
batchSize,
},
requestOptions,
);
Expand All @@ -593,18 +599,20 @@ export function createSearchClient({
* @param partialUpdateObjects.indexName - The `indexName` to update `objects` in.
* @param partialUpdateObjects.objects - The array of `objects` to update in the given Algolia `indexName`.
* @param partialUpdateObjects.createIfNotExists - To be provided if non-existing objects are passed, otherwise, the call will fail..
* @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.
* @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.
* @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `getTask` method and merged with the transporter requestOptions.
*/
async partialUpdateObjects(
{ indexName, objects, createIfNotExists, waitForTasks }: PartialUpdateObjectsOptions,
{ indexName, objects, createIfNotExists, waitForTasks, batchSize }: PartialUpdateObjectsOptions,
requestOptions?: RequestOptions,
): Promise<BatchResponse[]> {
return await this.chunkedBatch(
{
indexName,
objects,
action: createIfNotExists ? 'partialUpdateObject' : 'partialUpdateObjectNoCreate',
batchSize,
waitForTasks,
},
requestOptions,
Expand Down

0 comments on commit 7b40aa4

Please sign in to comment.