-
-
Notifications
You must be signed in to change notification settings - Fork 594
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
Performing batch transactions #922
Comments
I like the idea of having some way to send a batch from the JS SDK but I am not sure if the proposed API is the best one. I'd probably go with something like this: const transaction = Parse.Object.createTransaction();
someObject.destroy({ useMasterKey: true, transaction });
someObject.save({ transaction });
try {
transaction.commit();
} catch (e) {
transaction.abort();
} @JeromeDeLeon is this something that you'd be willed to tackle? |
That would be nice too. The reason I suggested that is because I want to use what is already existed in the codebase of PS. We could make use of |
Wait. I just saw that PS already incorporated the |
No.. there is no way to do it. Since the Parse Server can run in multiple processes at the same time, there is no warranty that two requests will go to the same process. In the case they go to different processes, you will not be able to use the same MongoDB session. So, the solution is actually use the |
// create unique ID or something
const transaction = Parse.Obejct.createTransaction();
// These operations will not be run until commit() is called
// maybe save it to array of operations
someObject.destroy({ useMasterKey: true, transaction });
someObject.save({ transaction });
try {
// since /batch already have abort operations no need to manually abort
transaction.commit();
} catch(e) {
console.log(e);
} What I have in mind is that when I call |
Yes. That's the idea. We will probably need the abort in the client side as well to revert the object states. |
Currently with the JS SDK (master, 2.11.0), there is no way to pass parameter "transaction" to the Parse Server. (Correct me if I am wrong) so the transactional stuff (which have been done on Parse Server) does not work with the JS SDK. My plan of attack is to make a PR which includes:
Does this make sense? @davimacedo |
I am trying to use a similar approach on server-side Parse.Cloud function! Getting the database object in cloud function and manually invoking createTransactionalSession at the beginning of my cloud function. And then invoking
I am stuck now and I have no idea why this does not work as expected...Perhaps the cloud function and the CRUD handlers they are not pointing to the same database object..? |
I think that your original idea of changing saveAll, destroyAll makes sense, will be a lot easier and a very good first step. Why don't you start with them? |
@davimacedo Yes I did give a try (#1090 ). Hope this is a good start to contribute. 'changing saveAll, destroyAll' in the JS SDK should be the top priority to support what have been done on Parse Server batch endpoint. I might get back to the cloud function approach later. |
Great job. It is a good start for sure. I've just left a comment over there. |
Any updates on this issue? |
Is there any update on this issue or a workaround? We have several use cases where transactions would be necessary (eg update 2 objects at the same time or rollback) |
I am also interested in an update🙂 |
interested. |
I'm interested in this too. |
Hello everyone, do you have any updates on this? By the way, it sounds like an amazing feature! |
I'm interested in this too. |
Added a bounty to this feature due to high demand. |
🎉 This change has been released in version 5.3.0-alpha.4 |
Is your feature request related to a problem? Please describe.
This was already supported in the PServer, but in JS-SDK, it limits us to only perform either save or delete but not both.
Describe the solution you'd like
It would be better if we could constructr a batch operation like:
and performs that sequentially.
Describe alternatives you've considered
Additional context
Also, using relations when doing batch operation is not allowed because you cannot add something to relation when it is new. I don't know if there's already a solution to this but my current implementation is to use
forkJoin([DeleteObjects(), SaveObjects()])
using RxJS.The text was updated successfully, but these errors were encountered: