-
Notifications
You must be signed in to change notification settings - Fork 21
feat(javascript): add replaceAllObjectsWithTransformation
#5008
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
feat(javascript): add replaceAllObjectsWithTransformation
#5008
Conversation
142a5c0
to
bc5ed6c
Compare
✔️ Code generated!
📊 Benchmark resultsBenchmarks performed on the method using a mock server, the results might not reflect the real-world performance.
|
bc5ed6c
to
405c5e4
Compare
ah actually that would mean breaking the signature, I need to check if there is some usage first |
0ee2dc0
to
4be66cf
Compare
breaking all of them at once in #5011 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so nice, gg
templates/javascript/clients/algoliasearch/builds/definition.mustache
Outdated
Show resolved
Hide resolved
* @param chunkedPush.indexName - The `indexName` to replace `objects` in. | ||
* @param chunkedPush.objects - The array of `objects` to store in the given Algolia `indexName`. | ||
* @param chunkedPush.action - The `batch` `action` to perform on the given array of `objects`, defaults to `addObject`. | ||
* @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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does waitForTasks
make sense here ? should it be waitForPush ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I copied chunkedBatch so it's usable the same way but since it's internal I can rename it if you want
const responses: Array<WatchResponse> = []; | ||
|
||
const objectEntries = objects.entries(); | ||
for (const [i, obj] of objectEntries) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what about https://stackoverflow.com/a/8495740 ? I feel like it's more efficient and more readable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've actually just copied chunkedBatch 🥶
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it's IE compatible as well? I can't remember what version we should support but I think it's 11?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
slice
is available everywhere
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i'll update both implems in a follow up pr!
if (waitForTasks) { | ||
for (const resp of responses) { | ||
if (resp.eventID === undefined || !resp.eventID) { | ||
throw new Error('received unexpected response from the push endpoint, eventID must not be undefined'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO this error checking should be in loop above, to early exit.
Also in that case there should be an error message in the response
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually had to put it here to satisfy the type checking (same for Go and other languages), I can duplicate it, but this one is required
🧭 What and Why
🎟 JIRA Ticket: https://algolia.atlassian.net/browse/DI-3894
Changes included:
this adds the helper to replace all of the content of an index by leveraging the transformation pipeline, i've inlined the chunkedPush logic but actually could be reused in the saveObjects and partialUpdateObjects methods as well, lmk