Skip to content

Commit 65d0c60

Browse files
algolia-botmillotp
andcommitted
only delete in case of failure (generated)
Co-authored-by: Pierre Millot <[email protected]>
1 parent a05f24a commit 65d0c60

File tree

38 files changed

+979
-297
lines changed

38 files changed

+979
-297
lines changed

clients/algoliasearch-client-csharp/.github/ISSUE_TEMPLATE/Bug_report.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ body:
2727
id: client
2828
attributes:
2929
label: Client
30-
description: Which API are you targetting?
30+
description: Which API are you targeting?
3131
options:
3232
- All
3333
- AB testing

clients/algoliasearch-client-dart/.github/ISSUE_TEMPLATE/Bug_report.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ body:
2727
id: client
2828
attributes:
2929
label: Client
30-
description: Which API are you targetting?
30+
description: Which API are you targeting?
3131
options:
3232
- All
3333
- AB testing

clients/algoliasearch-client-go/.github/ISSUE_TEMPLATE/Bug_report.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ body:
2727
id: client
2828
attributes:
2929
label: Client
30-
description: Which API are you targetting?
30+
description: Which API are you targeting?
3131
options:
3232
- All
3333
- AB testing

clients/algoliasearch-client-go/algolia/search/api_search.go

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

clients/algoliasearch-client-java/.github/ISSUE_TEMPLATE/Bug_report.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ body:
2727
id: client
2828
attributes:
2929
label: Client
30-
description: Which API are you targetting?
30+
description: Which API are you targeting?
3131
options:
3232
- All
3333
- AB testing

clients/algoliasearch-client-java/algoliasearch/src/main/java/com/algolia/api/SearchClient.java

Lines changed: 80 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -6572,24 +6572,6 @@ public <T> List<BatchResponse> chunkedBatch(
65726572
return chunkedBatch(indexName, objects, action, waitForTasks, 1000, requestOptions);
65736573
}
65746574

6575-
/**
6576-
* Push a new set of objects and remove all previous ones. Settings, synonyms and query rules are
6577-
* untouched. Replace all records in an index without any downtime. See
6578-
* https://api-clients-automation.netlify.app/docs/add-new-api-client#5-helpers for implementation
6579-
* details.
6580-
*
6581-
* @param indexName The `indexName` to replace `objects` in.
6582-
* @param objects The array of `objects` to store in the given Algolia `indexName`.
6583-
* @param batchSize The size of the chunk of `objects`. The number of `batch` calls will be equal
6584-
* to `length(objects) / batchSize`.
6585-
* @throws AlgoliaRetryException When the retry has failed on all hosts
6586-
* @throws AlgoliaApiException When the API sends an http error code
6587-
* @throws AlgoliaRuntimeException When an error occurred during the serialization
6588-
*/
6589-
public <T> ReplaceAllObjectsResponse replaceAllObjects(String indexName, Iterable<T> objects, int batchSize) {
6590-
return replaceAllObjects(indexName, objects, batchSize, null);
6591-
}
6592-
65936575
/**
65946576
* Helper: Saves the given array of objects in the given index. The `chunkedBatch` helper is used
65956577
* under the hood, which creates a `batch` requests with at most 1000 objects in it.
@@ -6822,6 +6804,40 @@ public <T> List<BatchResponse> partialUpdateObjects(
68226804
);
68236805
}
68246806

6807+
/**
6808+
* Push a new set of objects and remove all previous ones. Settings, synonyms and query rules are
6809+
* untouched. Replace all records in an index without any downtime. See
6810+
* https://api-clients-automation.netlify.app/docs/add-new-api-client#5-helpers for implementation
6811+
* details.
6812+
*
6813+
* @param indexName The `indexName` to replace `objects` in.
6814+
* @param objects The array of `objects` to store in the given Algolia `indexName`.
6815+
* @throws AlgoliaRetryException When the retry has failed on all hosts
6816+
* @throws AlgoliaApiException When the API sends an http error code
6817+
* @throws AlgoliaRuntimeException When an error occurred during the serialization
6818+
*/
6819+
public <T> ReplaceAllObjectsResponse replaceAllObjects(String indexName, Iterable<T> objects) {
6820+
return replaceAllObjects(indexName, objects, -1);
6821+
}
6822+
6823+
/**
6824+
* Push a new set of objects and remove all previous ones. Settings, synonyms and query rules are
6825+
* untouched. Replace all records in an index without any downtime. See
6826+
* https://api-clients-automation.netlify.app/docs/add-new-api-client#5-helpers for implementation
6827+
* details.
6828+
*
6829+
* @param indexName The `indexName` to replace `objects` in.
6830+
* @param objects The array of `objects` to store in the given Algolia `indexName`.
6831+
* @param batchSize The size of the chunk of `objects`. The number of `batch` calls will be equal
6832+
* to `length(objects) / batchSize`.
6833+
* @throws AlgoliaRetryException When the retry has failed on all hosts
6834+
* @throws AlgoliaApiException When the API sends an http error code
6835+
* @throws AlgoliaRuntimeException When an error occurred during the serialization
6836+
*/
6837+
public <T> ReplaceAllObjectsResponse replaceAllObjects(String indexName, Iterable<T> objects, int batchSize) {
6838+
return replaceAllObjects(indexName, objects, batchSize, null);
6839+
}
6840+
68256841
/**
68266842
* Push a new set of objects and remove all previous ones. Settings, synonyms and query rules are
68276843
* untouched. Replace all records in an index without any downtime. See
@@ -6847,47 +6863,57 @@ public <T> ReplaceAllObjectsResponse replaceAllObjects(
68476863
Random rnd = new Random();
68486864
String tmpIndexName = indexName + "_tmp_" + rnd.nextInt(100);
68496865

6850-
// Copy settings, synonyms and rules
6851-
UpdatedAtResponse copyOperationResponse = operationIndex(
6852-
indexName,
6853-
new OperationIndexParams()
6854-
.setOperation(OperationType.COPY)
6855-
.setDestination(tmpIndexName)
6856-
.addScope(ScopeType.SETTINGS)
6857-
.addScope(ScopeType.RULES)
6858-
.addScope(ScopeType.SYNONYMS),
6859-
requestOptions
6860-
);
6866+
if (batchSize == -1) {
6867+
batchSize = 1000;
6868+
}
68616869

6862-
// Save new objects
6863-
List<BatchResponse> batchResponses = chunkedBatch(tmpIndexName, objects, Action.ADD_OBJECT, true, batchSize, requestOptions);
6870+
try {
6871+
// Copy settings, synonyms and rules
6872+
UpdatedAtResponse copyOperationResponse = operationIndex(
6873+
indexName,
6874+
new OperationIndexParams()
6875+
.setOperation(OperationType.COPY)
6876+
.setDestination(tmpIndexName)
6877+
.addScope(ScopeType.SETTINGS)
6878+
.addScope(ScopeType.RULES)
6879+
.addScope(ScopeType.SYNONYMS),
6880+
requestOptions
6881+
);
68646882

6865-
waitForTask(tmpIndexName, copyOperationResponse.getTaskID(), requestOptions);
6883+
// Save new objects
6884+
List<BatchResponse> batchResponses = chunkedBatch(tmpIndexName, objects, Action.ADD_OBJECT, true, batchSize, requestOptions);
68666885

6867-
copyOperationResponse = operationIndex(
6868-
indexName,
6869-
new OperationIndexParams()
6870-
.setOperation(OperationType.COPY)
6871-
.setDestination(tmpIndexName)
6872-
.addScope(ScopeType.SETTINGS)
6873-
.addScope(ScopeType.RULES)
6874-
.addScope(ScopeType.SYNONYMS),
6875-
requestOptions
6876-
);
6877-
waitForTask(tmpIndexName, copyOperationResponse.getTaskID(), requestOptions);
6886+
waitForTask(tmpIndexName, copyOperationResponse.getTaskID(), requestOptions);
68786887

6879-
// Move temporary index to source index
6880-
UpdatedAtResponse moveOperationResponse = operationIndex(
6881-
tmpIndexName,
6882-
new OperationIndexParams().setOperation(OperationType.MOVE).setDestination(indexName),
6883-
requestOptions
6884-
);
6885-
waitForTask(tmpIndexName, moveOperationResponse.getTaskID(), requestOptions);
6888+
copyOperationResponse = operationIndex(
6889+
indexName,
6890+
new OperationIndexParams()
6891+
.setOperation(OperationType.COPY)
6892+
.setDestination(tmpIndexName)
6893+
.addScope(ScopeType.SETTINGS)
6894+
.addScope(ScopeType.RULES)
6895+
.addScope(ScopeType.SYNONYMS),
6896+
requestOptions
6897+
);
6898+
waitForTask(tmpIndexName, copyOperationResponse.getTaskID(), requestOptions);
6899+
6900+
// Move temporary index to source index
6901+
UpdatedAtResponse moveOperationResponse = operationIndex(
6902+
tmpIndexName,
6903+
new OperationIndexParams().setOperation(OperationType.MOVE).setDestination(indexName),
6904+
requestOptions
6905+
);
6906+
waitForTask(tmpIndexName, moveOperationResponse.getTaskID(), requestOptions);
6907+
6908+
return new ReplaceAllObjectsResponse()
6909+
.setCopyOperationResponse(copyOperationResponse)
6910+
.setBatchResponses(batchResponses)
6911+
.setMoveOperationResponse(moveOperationResponse);
6912+
} catch (Exception e) {
6913+
deleteIndex(tmpIndexName);
68866914

6887-
return new ReplaceAllObjectsResponse()
6888-
.setCopyOperationResponse(copyOperationResponse)
6889-
.setBatchResponses(batchResponses)
6890-
.setMoveOperationResponse(moveOperationResponse);
6915+
throw e;
6916+
}
68916917
}
68926918

68936919
/**

clients/algoliasearch-client-javascript/.github/ISSUE_TEMPLATE/Bug_report.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ body:
2727
id: client
2828
attributes:
2929
label: Client
30-
description: Which API are you targetting?
30+
description: Which API are you targeting?
3131
options:
3232
- All
3333
- AB testing

clients/algoliasearch-client-javascript/packages/client-search/src/searchClient.ts

Lines changed: 49 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -642,57 +642,63 @@ export function createSearchClient({
642642
const randomSuffix = Math.floor(Math.random() * 1000000) + 100000;
643643
const tmpIndexName = `${indexName}_tmp_${randomSuffix}`;
644644

645-
let copyOperationResponse = await this.operationIndex(
646-
{
647-
indexName,
648-
operationIndexParams: {
649-
operation: 'copy',
650-
destination: tmpIndexName,
651-
scope: ['settings', 'rules', 'synonyms'],
645+
try {
646+
let copyOperationResponse = await this.operationIndex(
647+
{
648+
indexName,
649+
operationIndexParams: {
650+
operation: 'copy',
651+
destination: tmpIndexName,
652+
scope: ['settings', 'rules', 'synonyms'],
653+
},
652654
},
653-
},
654-
requestOptions,
655-
);
655+
requestOptions,
656+
);
656657

657-
const batchResponses = await this.chunkedBatch(
658-
{ indexName: tmpIndexName, objects, waitForTasks: true, batchSize },
659-
requestOptions,
660-
);
658+
const batchResponses = await this.chunkedBatch(
659+
{ indexName: tmpIndexName, objects, waitForTasks: true, batchSize },
660+
requestOptions,
661+
);
661662

662-
await this.waitForTask({
663-
indexName: tmpIndexName,
664-
taskID: copyOperationResponse.taskID,
665-
});
663+
await this.waitForTask({
664+
indexName: tmpIndexName,
665+
taskID: copyOperationResponse.taskID,
666+
});
666667

667-
copyOperationResponse = await this.operationIndex(
668-
{
669-
indexName,
670-
operationIndexParams: {
671-
operation: 'copy',
672-
destination: tmpIndexName,
673-
scope: ['settings', 'rules', 'synonyms'],
668+
copyOperationResponse = await this.operationIndex(
669+
{
670+
indexName,
671+
operationIndexParams: {
672+
operation: 'copy',
673+
destination: tmpIndexName,
674+
scope: ['settings', 'rules', 'synonyms'],
675+
},
674676
},
675-
},
676-
requestOptions,
677-
);
678-
await this.waitForTask({
679-
indexName: tmpIndexName,
680-
taskID: copyOperationResponse.taskID,
681-
});
677+
requestOptions,
678+
);
679+
await this.waitForTask({
680+
indexName: tmpIndexName,
681+
taskID: copyOperationResponse.taskID,
682+
});
682683

683-
const moveOperationResponse = await this.operationIndex(
684-
{
684+
const moveOperationResponse = await this.operationIndex(
685+
{
686+
indexName: tmpIndexName,
687+
operationIndexParams: { operation: 'move', destination: indexName },
688+
},
689+
requestOptions,
690+
);
691+
await this.waitForTask({
685692
indexName: tmpIndexName,
686-
operationIndexParams: { operation: 'move', destination: indexName },
687-
},
688-
requestOptions,
689-
);
690-
await this.waitForTask({
691-
indexName: tmpIndexName,
692-
taskID: moveOperationResponse.taskID,
693-
});
693+
taskID: moveOperationResponse.taskID,
694+
});
694695

695-
return { copyOperationResponse, batchResponses, moveOperationResponse };
696+
return { copyOperationResponse, batchResponses, moveOperationResponse };
697+
} catch (error) {
698+
await this.deleteIndex({ indexName: tmpIndexName });
699+
700+
throw error;
701+
}
696702
},
697703

698704
async indexExists({ indexName }: GetSettingsProps): Promise<boolean> {

clients/algoliasearch-client-kotlin/.github/ISSUE_TEMPLATE/Bug_report.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ body:
2727
id: client
2828
attributes:
2929
label: Client
30-
description: Which API are you targetting?
30+
description: Which API are you targeting?
3131
options:
3232
- All
3333
- AB testing

clients/algoliasearch-client-php/.github/ISSUE_TEMPLATE/Bug_report.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ body:
2727
id: client
2828
attributes:
2929
label: Client
30-
description: Which API are you targetting?
30+
description: Which API are you targeting?
3131
options:
3232
- All
3333
- AB testing

0 commit comments

Comments
 (0)