Skip to content

Commit 3e1365f

Browse files
chore: generated code for commit de409078. [skip ci]
algolia/api-clients-automation@de40907 Co-authored-by: algolia-bot <[email protected]> Co-authored-by: Clément Vannicatte <[email protected]>
1 parent 375ba89 commit 3e1365f

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

Sources/Search/Extra/SearchClientExtension.swift

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,9 @@ public extension SearchClient {
457457
}
458458

459459
/// Replace all objects in an index
460+
///
461+
/// See https://api-clients-automation.netlify.app/docs/contributing/add-new-api-client#5-helpers for implementation
462+
/// details.
460463
/// - parameter objects: The new objects
461464
/// - parameter indexName: The name of the index where to replace the objects
462465
/// - parameter requestOptions: The request options
@@ -470,8 +473,7 @@ public extension SearchClient {
470473
) async throws -> ReplaceAllObjectsResponse {
471474
let tmpIndexName = try "\(indexName)_tmp_\(randomString())"
472475

473-
// Copy all index resources from production index
474-
let copyOperationResponse = try await operationIndex(
476+
var copyOperationResponse = try await operationIndex(
475477
indexName: indexName,
476478
operationIndexParams: OperationIndexParams(
477479
operation: .copy,
@@ -481,18 +483,26 @@ public extension SearchClient {
481483
requestOptions: requestOptions
482484
)
483485

484-
try await self.waitForTask(with: copyOperationResponse.taskID, in: indexName)
485-
486-
// Send records to the tmp index (batched)
487486
let batchResponses = try await self.chunkedBatch(
488487
indexName: tmpIndexName,
489488
objects: objects,
490489
waitForTasks: true,
491490
batchSize: batchSize,
492491
requestOptions: requestOptions
493492
)
493+
try await self.waitForTask(with: copyOperationResponse.taskID, in: tmpIndexName)
494+
495+
copyOperationResponse = try await operationIndex(
496+
indexName: indexName,
497+
operationIndexParams: OperationIndexParams(
498+
operation: .copy,
499+
destination: tmpIndexName,
500+
scope: [.rules, .settings, .synonyms]
501+
),
502+
requestOptions: requestOptions
503+
)
504+
try await self.waitForTask(with: copyOperationResponse.taskID, in: tmpIndexName)
494505

495-
// Move the temporary index to replace the main one
496506
let moveOperationResponse = try await self.operationIndex(
497507
indexName: tmpIndexName,
498508
operationIndexParams: OperationIndexParams(
@@ -501,7 +511,6 @@ public extension SearchClient {
501511
),
502512
requestOptions: requestOptions
503513
)
504-
505514
try await self.waitForTask(with: moveOperationResponse.taskID, in: tmpIndexName)
506515

507516
return ReplaceAllObjectsResponse(

0 commit comments

Comments
 (0)