Skip to content

Commit

Permalink
chore(kotlin): cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Fluf22 committed Oct 31, 2024
1 parent 7c25424 commit 8682e0d
Showing 1 changed file with 46 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -465,46 +465,50 @@ public suspend fun SearchClient.replaceAllObjects(
): ReplaceAllObjectsResponse {
val tmpIndexName = "${indexName}_tmp_${Random.nextInt(from = 0, until = 100)}"

var copy = operationIndex(
indexName = indexName,
operationIndexParams = OperationIndexParams(
operation = OperationType.Copy,
destination = tmpIndexName,
scope = listOf(ScopeType.Settings, ScopeType.Rules, ScopeType.Synonyms),
),
requestOptions = requestOptions,
)
try {
var copy = operationIndex(
indexName = indexName,
operationIndexParams = OperationIndexParams(
operation = OperationType.Copy,
destination = tmpIndexName,
scope = listOf(ScopeType.Settings, ScopeType.Rules, ScopeType.Synonyms),
),
requestOptions = requestOptions,
)

val batchResponses = this.chunkedBatch(
indexName = tmpIndexName,
objects = objects,
action = Action.AddObject,
waitForTask = true,
batchSize = batchSize,
requestOptions = requestOptions,
)
val batchResponses = this.chunkedBatch(
indexName = tmpIndexName,
objects = objects,
action = Action.AddObject,
waitForTask = true,
batchSize = batchSize,
requestOptions = requestOptions,
)

waitForTask(indexName = tmpIndexName, taskID = copy.taskID)
waitForTask(indexName = tmpIndexName, taskID = copy.taskID)

copy = operationIndex(
indexName = indexName,
operationIndexParams = OperationIndexParams(
operation = OperationType.Copy,
destination = tmpIndexName,
scope = listOf(ScopeType.Settings, ScopeType.Rules, ScopeType.Synonyms),
),
requestOptions = requestOptions,
)
waitForTask(indexName = tmpIndexName, taskID = copy.taskID)
copy = operationIndex(
indexName = indexName,
operationIndexParams = OperationIndexParams(
operation = OperationType.Copy,
destination = tmpIndexName,
scope = listOf(ScopeType.Settings, ScopeType.Rules, ScopeType.Synonyms),
),
requestOptions = requestOptions,
)
waitForTask(indexName = tmpIndexName, taskID = copy.taskID)

val move = operationIndex(
indexName = tmpIndexName,
operationIndexParams = OperationIndexParams(operation = OperationType.Move, destination = indexName),
requestOptions = requestOptions,
)
waitForTask(indexName = tmpIndexName, taskID = move.taskID)
val move = operationIndex(
indexName = tmpIndexName,
operationIndexParams = OperationIndexParams(operation = OperationType.Move, destination = indexName),
requestOptions = requestOptions,
)
waitForTask(indexName = tmpIndexName, taskID = move.taskID)

return ReplaceAllObjectsResponse(copy, batchResponses, move)
return ReplaceAllObjectsResponse(copy, batchResponses, move)
} finally {
deleteIndex(tmpIndexName)
}
}

/**
Expand Down Expand Up @@ -535,6 +539,13 @@ public fun securedApiKeyRemainingValidity(apiKey: String): Duration {
return validUntil - Clock.System.now()
}

/**
* Checks that an index exists.
*
* @param indexName The name of the index to check.
* @return true if the index exists, false otherwise.
* @throws AlgoliaApiException if an error occurs during the request.
*/
public suspend fun SearchClient.indexExists(indexName: String): Boolean {
try {
getSettings(indexName)
Expand Down

0 comments on commit 8682e0d

Please sign in to comment.