-
Notifications
You must be signed in to change notification settings - Fork 14
Add "wait" version of each method calling asynchronous part of MeiliSearch #12
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
Comments
We can pass an optional parameter, set by default to false, if user want to make it syncronous. Someting like turning def add_documents(self, documents, primary_key=None):
... into def add_documents(self, documents, primary_key=None, wait_for_update=False):
... The only problem is that we will still struggle with the Go SDK (and any other language that don't accpet optional params) |
I added your suggestion to the list! |
Suggestion 3Because it still needs the interval and the timeout options it becomes a long list of function parameters. def add_documents(self, documents, primary_key=None, wait_for_update=False, interval = 500, timeout= 2000): It could also look like this: def add_documents(self, documents, primary_key=None, wait_for_update=False, updateOptions = {
interval = 500,
timeout= 2000
}): ( see syntax in every language) Suggestion 2I have look into function chaining in PHP: It is not used for our use case
Which seems to be the case also for python. So I don't like about this option that requires a complete code restructure and does not seem to be a good practice in our case Suggestion 1.I tried to find a good naming for suggestion 1, those are my ideas. CamelCase version
snake case version
This function would still have its default parameters and added to that an object with the waiting options. Or just different parameter depending of the language let status = addDocumentsWaitUntilDone(docs, {
timeoutMs: 20000, // default 2000
interval: 500 // default 500
}) Making these variables optionnal My favoriteI think the most user-friendly is the suggestion 1. Because it does not require to struggle with additional parameters. It keeps your code more clean and by the name of the function you know what is going to happen and be returned. Mostly also, because in the case of suggestion 3, you could have a completely different return.
I also have difficulty imaging how we are going to document those function
Whereas if we go for suggestion 1
This is just an example without thought in phrasing but you get the general idea. So yes Suggestion 1 is more user friendly and will make for a better documentation. Integrating the solutionIt is not as duplicating as I thought it would be. async function addDocumentsWaitUntilDone(docs, waitOptions) {
const updateId = await addDocuments(docs)
return waitForPendingUpdate(updateId, waitOptions.timeouts, waitOptions.interval)
} Renaming the function ?
|
Done in every SDK!! |
Some actions in MeiliSearch are asynchronous (documents manipulation, settings...). The associated methods in the SDKs return information about the
update
with anenqueued
status and we don't know when the action is processed.We already provide, for most of the SDKs, the
waitForPendingUpdate
method (related #1). But it means this kind of usage (in ruby):Suggestion 1
We could provide a "wait" version of each method for better user experience, for example:
Naming
First of all, how can we name these methods?
A simple way would be to add a suffix to each method. I suggested
wait
without thinking about it a lot. So, I would like to read your ideas 🙂Coding
Instead of re-coding all the methods, we could find a way to generate the version of each concerned method, because there are just the same but with a
wait_for_pending_update
method.The goal is to avoid code duplication.
I haven't investigated this part yet.
Suggestion 2
Not sure if this solution is more user friendly than the other one. Investigation needed 😁
Coding
This solution would imply changing the return of all the current methods (big breaking). They should return an
Update
object instead of a JSON object containing information about the update. ThisUpdate
object should contain thewait_for_pending_update
method.Suggestion 3
This solution might be the easiest one to code, but problem with the Go!
A solution could be not to provide these methods for the Go language and wait for the demand/help of the community. Do not forget the
WaitForPendingUpdate
method is already available in the SDK Go.Conclusion
Even if you would rather have other suggestions than suggestion 1, I really like having your suggestions of naming for the suggestion 1, so that we can really compare them in term of user experience.
Suggestion 1 doesn't imply any breaking but we have to find a way to generate the code in every language. And a lot of tests would be added, at least one for each new method.
Suggestion 2 involves big breaking but seems easy to code: just an
Update
object to add.Suggestion 3 is the easiest one to code, and does not imply any breaking, but problem with the Go language! A lot of tests would be needed too.
=> The goal is to find what is the more user-friendly for our users, not only what we would like to code because it's easier 😇
The text was updated successfully, but these errors were encountered: