Skip to content

Commit

Permalink
feat(clients): expose waitForTasks to batch helpers [skip-bc] (genera…
Browse files Browse the repository at this point in the history
…ted)

algolia/api-clients-automation#4030

Co-authored-by: algolia-bot <[email protected]>
Co-authored-by: Clément Vannicatte <[email protected]>
  • Loading branch information
algolia-bot and shortcuts committed Oct 28, 2024
1 parent 00e515c commit f6c0444
Showing 1 changed file with 63 additions and 5 deletions.
68 changes: 63 additions & 5 deletions algoliasearch/src/main/java/com/algolia/api/SearchClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -6516,7 +6516,23 @@ public <T> List<BatchResponse> saveObjects(String indexName, Iterable<T> objects
* the transporter requestOptions. (optional)
*/
public <T> List<BatchResponse> saveObjects(String indexName, Iterable<T> objects, RequestOptions requestOptions) {
return chunkedBatch(indexName, objects, Action.ADD_OBJECT, false, 1000, requestOptions);
return saveObjects(indexName, objects, false, 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 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, RequestOptions requestOptions) {
return chunkedBatch(indexName, objects, Action.ADD_OBJECT, waitForTasks, 1000, requestOptions);
}

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

/**
Expand All @@ -6540,6 +6556,22 @@ public List<BatchResponse> deleteObjects(String indexName, List<String> objectID
* the transporter requestOptions. (optional)
*/
public List<BatchResponse> deleteObjects(String indexName, List<String> objectIDs, RequestOptions requestOptions) {
return deleteObjects(indexName, objectIDs, false, 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 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, RequestOptions requestOptions) {
List<Map<String, String>> objects = new ArrayList<>();

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

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

/**
Expand All @@ -6562,7 +6594,29 @@ public List<BatchResponse> deleteObjects(String indexName, List<String> objectID
* will fail.
*/
public <T> List<BatchResponse> partialUpdateObjects(String indexName, Iterable<T> objects, boolean createIfNotExists) {
return partialUpdateObjects(indexName, objects, createIfNotExists, null);
return partialUpdateObjects(indexName, objects, createIfNotExists, false, 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.
*/
public <T> List<BatchResponse> partialUpdateObjects(
String indexName,
Iterable<T> objects,
boolean createIfNotExists,
boolean waitForTasks
) {
return partialUpdateObjects(indexName, objects, createIfNotExists, waitForTasks, null);
}

/**
Expand All @@ -6574,20 +6628,24 @@ public <T> List<BatchResponse> partialUpdateObjects(String indexName, Iterable<T
* @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 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,
RequestOptions requestOptions
) {
return chunkedBatch(
indexName,
objects,
createIfNotExists ? Action.PARTIAL_UPDATE_OBJECT : Action.PARTIAL_UPDATE_OBJECT_NO_CREATE,
false,
waitForTasks,
1000,
requestOptions
);
Expand Down

0 comments on commit f6c0444

Please sign in to comment.