Skip to content

Commit 8c86573

Browse files
committed
chore(scala): cleanup
1 parent 65ab4f5 commit 8c86573

File tree

1 file changed

+43
-39
lines changed
  • clients/algoliasearch-client-scala/src/main/scala/algoliasearch/extension

1 file changed

+43
-39
lines changed

clients/algoliasearch-client-scala/src/main/scala/algoliasearch/extension/package.scala

Lines changed: 43 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -350,50 +350,54 @@ package object extension {
350350
}
351351
val tmpIndexName = s"${indexName}_tmp_${scala.util.Random.nextInt(100)}"
352352

353-
for {
354-
copy <- client.operationIndex(
355-
indexName = indexName,
356-
operationIndexParams = OperationIndexParams(
357-
operation = OperationType.Copy,
358-
destination = tmpIndexName,
359-
scope = Some(Seq(ScopeType.Settings, ScopeType.Rules, ScopeType.Synonyms))
360-
),
361-
requestOptions = requestOptions
362-
)
353+
try {
354+
for {
355+
copy <- client.operationIndex(
356+
indexName = indexName,
357+
operationIndexParams = OperationIndexParams(
358+
operation = OperationType.Copy,
359+
destination = tmpIndexName,
360+
scope = Some(Seq(ScopeType.Settings, ScopeType.Rules, ScopeType.Synonyms))
361+
),
362+
requestOptions = requestOptions
363+
)
363364

364-
batchResponses <- chunkedBatch(
365-
indexName = tmpIndexName,
366-
objects = objects,
367-
action = Action.AddObject,
368-
waitForTasks = true,
369-
batchSize = batchSize,
370-
requestOptions = requestOptions
371-
)
365+
batchResponses <- chunkedBatch(
366+
indexName = tmpIndexName,
367+
objects = objects,
368+
action = Action.AddObject,
369+
waitForTasks = true,
370+
batchSize = batchSize,
371+
requestOptions = requestOptions
372+
)
372373

373-
_ <- client.waitTask(indexName = tmpIndexName, taskID = copy.taskID, requestOptions = requestOptions)
374+
_ <- client.waitTask(indexName = tmpIndexName, taskID = copy.taskID, requestOptions = requestOptions)
374375

375-
copy <- client.operationIndex(
376-
indexName = indexName,
377-
operationIndexParams = OperationIndexParams(
378-
operation = OperationType.Copy,
379-
destination = tmpIndexName,
380-
scope = Some(Seq(ScopeType.Settings, ScopeType.Rules, ScopeType.Synonyms))
381-
),
382-
requestOptions = requestOptions
383-
)
384-
_ <- client.waitTask(indexName = tmpIndexName, taskID = copy.taskID, requestOptions = requestOptions)
376+
copy <- client.operationIndex(
377+
indexName = indexName,
378+
operationIndexParams = OperationIndexParams(
379+
operation = OperationType.Copy,
380+
destination = tmpIndexName,
381+
scope = Some(Seq(ScopeType.Settings, ScopeType.Rules, ScopeType.Synonyms))
382+
),
383+
requestOptions = requestOptions
384+
)
385+
_ <- client.waitTask(indexName = tmpIndexName, taskID = copy.taskID, requestOptions = requestOptions)
385386

386-
move <- client.operationIndex(
387-
indexName = tmpIndexName,
388-
operationIndexParams = OperationIndexParams(operation = OperationType.Move, destination = indexName),
389-
requestOptions = requestOptions
387+
move <- client.operationIndex(
388+
indexName = tmpIndexName,
389+
operationIndexParams = OperationIndexParams(operation = OperationType.Move, destination = indexName),
390+
requestOptions = requestOptions
391+
)
392+
_ <- client.waitTask(indexName = tmpIndexName, taskID = move.taskID, requestOptions = requestOptions)
393+
} yield ReplaceAllObjectsResponse(
394+
copyOperationResponse = copy,
395+
batchResponses = batchResponses,
396+
moveOperationResponse = move
390397
)
391-
_ <- client.waitTask(indexName = tmpIndexName, taskID = move.taskID, requestOptions = requestOptions)
392-
} yield ReplaceAllObjectsResponse(
393-
copyOperationResponse = copy,
394-
batchResponses = batchResponses,
395-
moveOperationResponse = move
396-
)
398+
} finally {
399+
client.deleteIndex(tmpIndexName)
400+
}
397401
}
398402

399403
def indexExists(indexName: String)(implicit ec: ExecutionContext): Future[Boolean] = {

0 commit comments

Comments
 (0)