Skip to content

Commit 256482c

Browse files
authored
fix(clients): add batchSize to accountCopyIndex (#5181)
1 parent fa17353 commit 256482c

File tree

5 files changed

+24
-7
lines changed

5 files changed

+24
-7
lines changed

scripts/cts/testServer/accountCopyIndex.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const aciState: Record<
2525
export function assertValidAccountCopyIndex(expectedCount: number): void {
2626
expect(Object.keys(aciState)).to.have.length(expectedCount);
2727
for (const lang in aciState) {
28-
expect(aciState[lang].waitTaskCount).to.equal(4);
28+
expect(aciState[lang].waitTaskCount).to.equal(5);
2929
}
3030
}
3131

@@ -167,23 +167,25 @@ function addRoutes(app: Express): void {
167167
app.post('/1/indexes/:indexName/browse', (req, res) => {
168168
const lang = req.params.indexName.match(/^cts_e2e_account_copy_index_source_(.*)$/)?.[1] as string;
169169
expect(aciState).to.include.keys(lang);
170+
expect(req.body.hitsPerPage).to.equal(2);
170171

171172
aciState[lang].browseObjectsCount++;
172173

173174
res.json({
174175
page: 0,
175-
nbHits: 1,
176+
nbHits: 4,
176177
nbPages: 1,
177-
hitsPerPage: 1000,
178+
hitsPerPage: req.body.hitsPerPage,
178179
query: '',
179180
params: '',
180-
hits: [{ objectID: 'bar' }],
181+
hits: [{ objectID: 'bar' }, { objectID: 'foo' }, { objectID: 'baz' }, { objectID: 'qux' }],
181182
});
182183
});
183184

184185
app.post('/1/indexes/:indexName/batch', (req, res) => {
185186
const lang = req.params.indexName.match(/^cts_e2e_account_copy_index_destination_(.*)$/)?.[1] as string;
186187
expect(aciState).to.include.keys(lang);
188+
expect(req.body.requests).to.have.lengthOf(2);
187189

188190
aciState[lang].saveObjectsCount++;
189191

specs/search/helpers/accountCopyIndex.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@ method:
4040
required: true
4141
schema:
4242
type: string
43+
- in: query
44+
name: batchSize
45+
description: The size of the chunk of `objects`. Defaults to 1000.
46+
required: false
47+
schema:
48+
type: integer
49+
default: 1000
4350
responses:
4451
'400':
4552
$ref: '../../common/responses/IndexInSameApp.yml'

templates/javascript/clients/client/api/nodeHelpers.mustache

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,11 @@ generateSecuredApiKey: ({
4545
* @param accountCopyIndex.destinationAppID - The application ID to write the index to.
4646
* @param accountCopyIndex.destinationApiKey - The API Key of the `destinationAppID` to write the index to, must have write ACLs.
4747
* @param accountCopyIndex.destinationIndexName - The name of the index to write the copied index to.
48+
* @param accountCopyIndex.batchSize - The size of the chunk of `objects`. Defaults to 1000.
4849
* @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `setSettings`, `saveRules`, `saveSynonyms` and `saveObjects` method and merged with the transporter requestOptions.
4950
*/
5051
async accountCopyIndex(
51-
{ sourceIndexName, destinationAppID, destinationApiKey, destinationIndexName }: AccountCopyIndexOptions,
52+
{ sourceIndexName, destinationAppID, destinationApiKey, destinationIndexName, batchSize }: AccountCopyIndexOptions,
5253
requestOptions?: RequestOptions | undefined,
5354
): Promise<void> {
5455
const responses: Array<{ taskID: UpdatedAtResponse['taskID'] }> = [];
@@ -118,10 +119,11 @@ async accountCopyIndex(
118119

119120
await this.browseObjects({
120121
indexName: sourceIndexName,
122+
browseParams: batchSize ? { hitsPerPage: batchSize } : undefined,
121123
async aggregator(response: BrowseResponse) {
122124
responses.push(
123125
...(await destinationClient.saveObjects(
124-
{ indexName: destinationIndexName, objects: response.hits },
126+
{ indexName: destinationIndexName, objects: response.hits, batchSize },
125127
requestOptions,
126128
)),
127129
);

templates/javascript/clients/client/model/clientMethodProps.mustache

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,11 @@ export type AccountCopyIndexOptions = {
210210
* The name of the index to write the copy in.
211211
*/
212212
destinationIndexName: string;
213+
214+
/**
215+
* The size of the chunk of `objects`. Defaults to 1000.
216+
*/
217+
batchSize?: number | undefined;
213218
};
214219
{{/isAlgoliasearchClient}}
215220
{{/isSearchClient}}

tests/CTS/client/search/accountCopyIndex.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
"sourceIndexName": "cts_e2e_account_copy_index_source_${{language}}",
2323
"destinationAppID": "test-app-id-destination",
2424
"destinationApiKey": "test-api-key-destination",
25-
"destinationIndexName": "cts_e2e_account_copy_index_destination_${{language}}"
25+
"destinationIndexName": "cts_e2e_account_copy_index_destination_${{language}}",
26+
"batchSize": 2
2627
}
2728
}
2829
]

0 commit comments

Comments
 (0)