Skip to content

Commit 2ebd1f9

Browse files
committed
fix: timeout
1 parent a160398 commit 2ebd1f9

File tree

2 files changed

+12
-47
lines changed

2 files changed

+12
-47
lines changed

templates/go/search_helpers.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,7 @@ func (c *APIClient) ChunkedPush(indexName string, objects []map[string]any, acti
676676

677677
return true, err
678678
},
679-
WithTimeout(func(count int) time.Duration { return time.Duration(min(200*count, 5000)) * time.Millisecond }), WithMaxRetries(50),
679+
WithTimeout(func(count int) time.Duration { return time.Duration(min(500*count, 5000)) * time.Millisecond }), WithMaxRetries(50),
680680
)
681681
if err != nil {
682682
return nil, err

templates/javascript/clients/algoliasearch/builds/definition.mustache

Lines changed: 11 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export type Algoliasearch = SearchClient & {
4444
* @param saveObjects.waitForTasks - Whether or not we should wait until every `batch` tasks has been processed, this operation may slow the total execution time of this method but is more reliable.
4545
* @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `batch` method and merged with the transporter requestOptions.
4646
*/
47-
saveObjectsWithTransformation: (options: SaveObjectsOptions, requestOptions?: RequestOptions | undefined) => Promise<WatchResponse>;
47+
saveObjectsWithTransformation: (options: SaveObjectsOptions, requestOptions?: RequestOptions | undefined) => Promise<Array<WatchResponse>>;
4848

4949
/**
5050
* Helper: Similar to the `partialUpdateObjects` method but requires a Push connector (https://www.algolia.com/doc/guides/sending-and-managing-data/send-and-update-your-data/connectors/push/) to be created first, in order to transform records before indexing them to Algolia. The `region` must have been passed to the client instantiation method.
@@ -58,7 +58,7 @@ export type Algoliasearch = SearchClient & {
5858
* @param partialUpdateObjects.waitForTasks - Whether or not we should wait until every `batch` tasks has been processed, this operation may slow the total execution time of this method but is more reliable.
5959
* @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `getTask` method and merged with the transporter requestOptions.
6060
*/
61-
partialUpdateObjectsWithTransformation: (options: PartialUpdateObjectsOptions, requestOptions?: RequestOptions | undefined) => Promise<WatchResponse>;
61+
partialUpdateObjectsWithTransformation: (options: PartialUpdateObjectsOptions, requestOptions?: RequestOptions | undefined) => Promise<Array<WatchResponse>>;
6262

6363
/**
6464
* Helper: Similar to the `replaceAllObjects` method but requires a Push connector (https://www.algolia.com/doc/guides/sending-and-managing-data/send-and-update-your-data/connectors/push/) to be created first, in order to transform records before indexing them to Algolia. The `region` must have been passed to the client instantiation method.
@@ -86,9 +86,10 @@ export type Algoliasearch = SearchClient & {
8686
* @param chunkedPush.action - The `batch` `action` to perform on the given array of `objects`, defaults to `addObject`.
8787
* @param chunkedPush.waitForTasks - Whether or not we should wait until every `batch` tasks has been processed, this operation may slow the total execution time of this method but is more reliable.
8888
* @param chunkedPush.batchSize - The size of the chunk of `objects`. The number of `batch` calls will be equal to `length(objects) / batchSize`. Defaults to 1000.
89+
* @param chunkedPush.referenceIndexName - This is required when targeting an index that does not have a push connector setup (e.g. a tmp index), but you wish to attach another index's transformation to it (e.g. the source index name).
8990
* @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `getEvent` method and merged with the transporter requestOptions.
9091
*/
91-
chunkedPush: (options: ChunkedBatchOptions, requestOptions?: RequestOptions) => Promise<Array<WatchResponse>>;
92+
chunkedPush: (options: ChunkedBatchOptions & { referenceIndexName?: string }, requestOptions?: RequestOptions) => Promise<Array<WatchResponse>>;
9293
};
9394

9495
export type TransformationOptions = {
@@ -127,55 +128,19 @@ export function algoliasearch(
127128
return {
128129
...client,
129130
130-
async saveObjectsWithTransformation({ indexName, objects, waitForTasks }, requestOptions): Promise<WatchResponse> {
131-
if (!ingestionTransporter) {
132-
throw new Error('`transformation.region` must be provided at client instantiation before calling this method.');
133-
}
134-
135-
if (!options?.transformation?.region) {
136-
throw new Error('`region` must be provided when leveraging the transformation pipeline');
137-
}
138-
139-
return ingestionTransporter?.push(
140-
{
141-
indexName,
142-
watch: waitForTasks,
143-
pushTaskPayload: {
144-
action: 'addObject',
145-
records: objects as PushTaskRecords[],
146-
},
147-
},
148-
requestOptions,
149-
);
131+
async saveObjectsWithTransformation({ indexName, objects, waitForTasks }, requestOptions): Promise<Array<WatchResponse>> {
132+
return this.chunkedPush({ indexName, objects, action: 'addObject' });
150133
},
151134

152135
async partialUpdateObjectsWithTransformation(
153136
{ indexName, objects, createIfNotExists, waitForTasks },
154137
requestOptions,
155-
): Promise<WatchResponse> {
156-
if (!ingestionTransporter) {
157-
throw new Error('`transformation.region` must be provided at client instantiation before calling this method.');
158-
}
159-
160-
if (!options?.transformation?.region) {
161-
throw new Error('`region` must be provided when leveraging the transformation pipeline');
162-
}
163-
164-
return ingestionTransporter?.push(
165-
{
166-
indexName,
167-
watch: waitForTasks,
168-
pushTaskPayload: {
169-
action: createIfNotExists ? 'partialUpdateObject' : 'partialUpdateObjectNoCreate',
170-
records: objects as PushTaskRecords[],
171-
},
172-
},
173-
requestOptions,
174-
);
138+
): Promise<Array<WatchResponse>> {
139+
return this.chunkedPush({ indexName, objects, action: createIfNotExists ? 'partialUpdateObject' : 'partialUpdateObjectNoCreate' });
175140
},
176141

177142
async chunkedPush(
178-
{ indexName, objects, action = 'addObject', waitForTasks, batchSize = 1000 }: ChunkedBatchOptions,
143+
{ indexName, objects, action = 'addObject', waitForTasks, batchSize = 1000, referenceIndexName }: ChunkedBatchOptions & { referenceIndexName?: string },
179144
requestOptions?: RequestOptions,
180145
): Promise<Array<WatchResponse>> {
181146
if (!ingestionTransporter) {
@@ -195,7 +160,7 @@ export function algoliasearch(
195160
if (records.length === batchSize || i === objects.length - 1) {
196161
responses.push(
197162
await ingestionTransporter.push(
198-
{ indexName, pushTaskPayload: { action, records }, watch: waitForTasks },
163+
{ indexName, pushTaskPayload: { action, records }, referenceIndexName },
199164
requestOptions,
200165
),
201166
);
@@ -272,7 +237,7 @@ export function algoliasearch(
272237
);
273238

274239
const watchResponses = await this.chunkedPush(
275-
{ indexName: tmpIndexName, objects, waitForTasks: true, batchSize },
240+
{ indexName: tmpIndexName, objects, waitForTasks: true, batchSize, referenceIndexName: indexName },
276241
requestOptions,
277242
);
278243

0 commit comments

Comments
 (0)