Skip to content

Commit 76ecbdd

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 422e3cb commit 76ecbdd

File tree

1 file changed

+79
-3
lines changed

1 file changed

+79
-3
lines changed

algoliasearch/src/main/java/com/algolia/api/SearchClient.java

Lines changed: 79 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6612,7 +6612,31 @@ public <T> List<BatchResponse> saveObjects(String indexName, Iterable<T> objects
66126612
* the transporter requestOptions. (optional)
66136613
*/
66146614
public <T> List<BatchResponse> saveObjects(String indexName, Iterable<T> objects, boolean waitForTasks, RequestOptions requestOptions) {
6615-
return chunkedBatch(indexName, objects, Action.ADD_OBJECT, waitForTasks, 1000, requestOptions);
6615+
return saveObjects(indexName, objects, false, 1000, requestOptions);
6616+
}
6617+
6618+
/**
6619+
* Helper: Saves the given array of objects in the given index. The `chunkedBatch` helper is used
6620+
* under the hood, which creates a `batch` requests with at most 1000 objects in it.
6621+
*
6622+
* @param indexName The `indexName` to replace `objects` in.
6623+
* @param objects The array of `objects` to store in the given Algolia `indexName`.
6624+
* @param waitForTasks - Whether or not we should wait until every `batch` tasks has been
6625+
* processed, this operation may slow the total execution time of this method but is more
6626+
* reliable.
6627+
* @param batchSize The size of the chunk of `objects`. The number of `batch` calls will be equal
6628+
* to `length(objects) / batchSize`.
6629+
* @param requestOptions The requestOptions to send along with the query, they will be merged with
6630+
* the transporter requestOptions. (optional)
6631+
*/
6632+
public <T> List<BatchResponse> saveObjects(
6633+
String indexName,
6634+
Iterable<T> objects,
6635+
boolean waitForTasks,
6636+
int batchSize,
6637+
RequestOptions requestOptions
6638+
) {
6639+
return chunkedBatch(indexName, objects, Action.ADD_OBJECT, waitForTasks, batchSize, requestOptions);
66166640
}
66176641

66186642
/**
@@ -6652,6 +6676,30 @@ public List<BatchResponse> deleteObjects(String indexName, List<String> objectID
66526676
* the transporter requestOptions. (optional)
66536677
*/
66546678
public List<BatchResponse> deleteObjects(String indexName, List<String> objectIDs, boolean waitForTasks, RequestOptions requestOptions) {
6679+
return deleteObjects(indexName, objectIDs, false, 1000, null);
6680+
}
6681+
6682+
/**
6683+
* Helper: Deletes every records for the given objectIDs. The `chunkedBatch` helper is used under
6684+
* the hood, which creates a `batch` requests with at most 1000 objectIDs in it.
6685+
*
6686+
* @param indexName The `indexName` to delete `objectIDs` from.
6687+
* @param objectIDs The array of `objectIDs` to delete from the `indexName`.
6688+
* @param waitForTasks - Whether or not we should wait until every `batch` tasks has been
6689+
* processed, this operation may slow the total execution time of this method but is more
6690+
* reliable.
6691+
* @param batchSize The size of the chunk of `objects`. The number of `batch` calls will be equal
6692+
* to `length(objects) / batchSize`.
6693+
* @param requestOptions The requestOptions to send along with the query, they will be merged with
6694+
* the transporter requestOptions. (optional)
6695+
*/
6696+
public List<BatchResponse> deleteObjects(
6697+
String indexName,
6698+
List<String> objectIDs,
6699+
boolean waitForTasks,
6700+
int batchSize,
6701+
RequestOptions requestOptions
6702+
) {
66556703
List<Map<String, String>> objects = new ArrayList<>();
66566704

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

6663-
return chunkedBatch(indexName, objects, Action.DELETE_OBJECT, waitForTasks, 1000, requestOptions);
6711+
return chunkedBatch(indexName, objects, Action.DELETE_OBJECT, waitForTasks, batchSize, requestOptions);
66646712
}
66656713

66666714
/**
@@ -6720,13 +6768,41 @@ public <T> List<BatchResponse> partialUpdateObjects(
67206768
boolean createIfNotExists,
67216769
boolean waitForTasks,
67226770
RequestOptions requestOptions
6771+
) {
6772+
return partialUpdateObjects(indexName, objects, createIfNotExists, waitForTasks, 1000, null);
6773+
}
6774+
6775+
/**
6776+
* Helper: Replaces object content of all the given objects according to their respective
6777+
* `objectID` field. The `chunkedBatch` helper is used under the hood, which creates a `batch`
6778+
* requests with at most 1000 objects in it.
6779+
*
6780+
* @param indexName The `indexName` to update `objects` in.
6781+
* @param objects The array of `objects` to update in the given Algolia `indexName`.
6782+
* @param createIfNotExists To be provided if non-existing objects are passed, otherwise, the call
6783+
* will fail.
6784+
* @param waitForTasks - Whether or not we should wait until every `batch` tasks has been
6785+
* processed, this operation may slow the total execution time of this method but is more
6786+
* reliable.
6787+
* @param batchSize The size of the chunk of `objects`. The number of `batch` calls will be equal
6788+
* to `length(objects) / batchSize`.
6789+
* @param requestOptions The requestOptions to send along with the query, they will be merged with
6790+
* the transporter requestOptions. (optional)
6791+
*/
6792+
public <T> List<BatchResponse> partialUpdateObjects(
6793+
String indexName,
6794+
Iterable<T> objects,
6795+
boolean createIfNotExists,
6796+
boolean waitForTasks,
6797+
int batchSize,
6798+
RequestOptions requestOptions
67236799
) {
67246800
return chunkedBatch(
67256801
indexName,
67266802
objects,
67276803
createIfNotExists ? Action.PARTIAL_UPDATE_OBJECT : Action.PARTIAL_UPDATE_OBJECT_NO_CREATE,
67286804
waitForTasks,
6729-
1000,
6805+
batchSize,
67306806
requestOptions
67316807
);
67326808
}

0 commit comments

Comments
 (0)