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 422e3cb commit 76ecbdd
Showing 1 changed file with 79 additions and 3 deletions.
82 changes: 79 additions & 3 deletions algoliasearch/src/main/java/com/algolia/api/SearchClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -6612,7 +6612,31 @@ public <T> List<BatchResponse> saveObjects(String indexName, Iterable<T> objects
* the transporter requestOptions. (optional)
*/
public <T> List<BatchResponse> saveObjects(String indexName, Iterable<T> objects, boolean waitForTasks, RequestOptions requestOptions) {
return chunkedBatch(indexName, objects, Action.ADD_OBJECT, waitForTasks, 1000, requestOptions);
return saveObjects(indexName, objects, false, 1000, requestOptions);
}

/**
* Helper: Saves the given array of objects in the given index. The `chunkedBatch` helper is used
* under the hood, which creates a `batch` requests with at most 1000 objects in it.
*
* @param indexName The `indexName` to replace `objects` in.
* @param objects The array of `objects` to store in the given Algolia `indexName`.
* @param 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 batchSize The size of the chunk of `objects`. The number of `batch` calls will be equal
* to `length(objects) / batchSize`.
* @param requestOptions The requestOptions to send along with the query, they will be merged with
* the transporter requestOptions. (optional)
*/
public <T> List<BatchResponse> saveObjects(
String indexName,
Iterable<T> objects,
boolean waitForTasks,
int batchSize,
RequestOptions requestOptions
) {
return chunkedBatch(indexName, objects, Action.ADD_OBJECT, waitForTasks, batchSize, requestOptions);
}

/**
Expand Down Expand Up @@ -6652,6 +6676,30 @@ public List<BatchResponse> deleteObjects(String indexName, List<String> objectID
* the transporter requestOptions. (optional)
*/
public List<BatchResponse> deleteObjects(String indexName, List<String> objectIDs, boolean waitForTasks, RequestOptions requestOptions) {
return deleteObjects(indexName, objectIDs, false, 1000, null);
}

/**
* 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.
*
* @param indexName The `indexName` to delete `objectIDs` from.
* @param objectIDs The array of `objectIDs` to delete from the `indexName`.
* @param 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 batchSize The size of the chunk of `objects`. The number of `batch` calls will be equal
* to `length(objects) / batchSize`.
* @param requestOptions The requestOptions to send along with the query, they will be merged with
* the transporter requestOptions. (optional)
*/
public List<BatchResponse> deleteObjects(
String indexName,
List<String> objectIDs,
boolean waitForTasks,
int batchSize,
RequestOptions requestOptions
) {
List<Map<String, String>> objects = new ArrayList<>();

for (String id : objectIDs) {
Expand All @@ -6660,7 +6708,7 @@ public List<BatchResponse> deleteObjects(String indexName, List<String> objectID
objects.add(obj);
}

return chunkedBatch(indexName, objects, Action.DELETE_OBJECT, waitForTasks, 1000, requestOptions);
return chunkedBatch(indexName, objects, Action.DELETE_OBJECT, waitForTasks, batchSize, requestOptions);
}

/**
Expand Down Expand Up @@ -6720,13 +6768,41 @@ public <T> List<BatchResponse> partialUpdateObjects(
boolean createIfNotExists,
boolean waitForTasks,
RequestOptions requestOptions
) {
return partialUpdateObjects(indexName, objects, createIfNotExists, waitForTasks, 1000, null);
}

/**
* 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.
*
* @param indexName The `indexName` to update `objects` in.
* @param objects The array of `objects` to update in the given Algolia `indexName`.
* @param createIfNotExists To be provided if non-existing objects are passed, otherwise, the call
* will fail.
* @param 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 batchSize The size of the chunk of `objects`. The number of `batch` calls will be equal
* to `length(objects) / batchSize`.
* @param requestOptions The requestOptions to send along with the query, they will be merged with
* the transporter requestOptions. (optional)
*/
public <T> List<BatchResponse> partialUpdateObjects(
String indexName,
Iterable<T> objects,
boolean createIfNotExists,
boolean waitForTasks,
int batchSize,
RequestOptions requestOptions
) {
return chunkedBatch(
indexName,
objects,
createIfNotExists ? Action.PARTIAL_UPDATE_OBJECT : Action.PARTIAL_UPDATE_OBJECT_NO_CREATE,
waitForTasks,
1000,
batchSize,
requestOptions
);
}
Expand Down

0 comments on commit 76ecbdd

Please sign in to comment.