Skip to content

Commit 8682e0d

Browse files
committed
chore(kotlin): cleanup
1 parent 7c25424 commit 8682e0d

File tree

1 file changed

+46
-35
lines changed
  • clients/algoliasearch-client-kotlin/client/src/commonMain/kotlin/com/algolia/client/extensions

1 file changed

+46
-35
lines changed

clients/algoliasearch-client-kotlin/client/src/commonMain/kotlin/com/algolia/client/extensions/SearchClient.kt

Lines changed: 46 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -465,46 +465,50 @@ public suspend fun SearchClient.replaceAllObjects(
465465
): ReplaceAllObjectsResponse {
466466
val tmpIndexName = "${indexName}_tmp_${Random.nextInt(from = 0, until = 100)}"
467467

468-
var copy = operationIndex(
469-
indexName = indexName,
470-
operationIndexParams = OperationIndexParams(
471-
operation = OperationType.Copy,
472-
destination = tmpIndexName,
473-
scope = listOf(ScopeType.Settings, ScopeType.Rules, ScopeType.Synonyms),
474-
),
475-
requestOptions = requestOptions,
476-
)
468+
try {
469+
var copy = operationIndex(
470+
indexName = indexName,
471+
operationIndexParams = OperationIndexParams(
472+
operation = OperationType.Copy,
473+
destination = tmpIndexName,
474+
scope = listOf(ScopeType.Settings, ScopeType.Rules, ScopeType.Synonyms),
475+
),
476+
requestOptions = requestOptions,
477+
)
477478

478-
val batchResponses = this.chunkedBatch(
479-
indexName = tmpIndexName,
480-
objects = objects,
481-
action = Action.AddObject,
482-
waitForTask = true,
483-
batchSize = batchSize,
484-
requestOptions = requestOptions,
485-
)
479+
val batchResponses = this.chunkedBatch(
480+
indexName = tmpIndexName,
481+
objects = objects,
482+
action = Action.AddObject,
483+
waitForTask = true,
484+
batchSize = batchSize,
485+
requestOptions = requestOptions,
486+
)
486487

487-
waitForTask(indexName = tmpIndexName, taskID = copy.taskID)
488+
waitForTask(indexName = tmpIndexName, taskID = copy.taskID)
488489

489-
copy = operationIndex(
490-
indexName = indexName,
491-
operationIndexParams = OperationIndexParams(
492-
operation = OperationType.Copy,
493-
destination = tmpIndexName,
494-
scope = listOf(ScopeType.Settings, ScopeType.Rules, ScopeType.Synonyms),
495-
),
496-
requestOptions = requestOptions,
497-
)
498-
waitForTask(indexName = tmpIndexName, taskID = copy.taskID)
490+
copy = operationIndex(
491+
indexName = indexName,
492+
operationIndexParams = OperationIndexParams(
493+
operation = OperationType.Copy,
494+
destination = tmpIndexName,
495+
scope = listOf(ScopeType.Settings, ScopeType.Rules, ScopeType.Synonyms),
496+
),
497+
requestOptions = requestOptions,
498+
)
499+
waitForTask(indexName = tmpIndexName, taskID = copy.taskID)
499500

500-
val move = operationIndex(
501-
indexName = tmpIndexName,
502-
operationIndexParams = OperationIndexParams(operation = OperationType.Move, destination = indexName),
503-
requestOptions = requestOptions,
504-
)
505-
waitForTask(indexName = tmpIndexName, taskID = move.taskID)
501+
val move = operationIndex(
502+
indexName = tmpIndexName,
503+
operationIndexParams = OperationIndexParams(operation = OperationType.Move, destination = indexName),
504+
requestOptions = requestOptions,
505+
)
506+
waitForTask(indexName = tmpIndexName, taskID = move.taskID)
506507

507-
return ReplaceAllObjectsResponse(copy, batchResponses, move)
508+
return ReplaceAllObjectsResponse(copy, batchResponses, move)
509+
} finally {
510+
deleteIndex(tmpIndexName)
511+
}
508512
}
509513

510514
/**
@@ -535,6 +539,13 @@ public fun securedApiKeyRemainingValidity(apiKey: String): Duration {
535539
return validUntil - Clock.System.now()
536540
}
537541

542+
/**
543+
* Checks that an index exists.
544+
*
545+
* @param indexName The name of the index to check.
546+
* @return true if the index exists, false otherwise.
547+
* @throws AlgoliaApiException if an error occurs during the request.
548+
*/
538549
public suspend fun SearchClient.indexExists(indexName: String): Boolean {
539550
try {
540551
getSettings(indexName)

0 commit comments

Comments
 (0)