Skip to content
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

Batch transaction #5849

Merged
merged 30 commits into from Jul 31, 2019

Conversation

@davimacedo
Copy link
Member

commented Jul 26, 2019

This PR empowers the current Parse Server's /batch/ endpoint with transaction capability for both MongoDB (>4.0) and Postgres. You can find an example of request below:

        request({
          method: 'POST',
          headers: headers,
          url: 'http://localhost:8378/1/batch',
          body: JSON.stringify({
            requests: [
              {
                method: 'POST',
                path: '/1/classes/MyObject',
                body: { key: 'value1' },
              },
              {
                method: 'POST',
                path: '/1/classes/MyObject',
                body: { key: 'value2' },
              },
            ],
            transaction: true,
          }),
        })

Close #2159

@davimacedo davimacedo force-pushed the back4app:batchTransaction branch from aca4e49 to 142acde Jul 26, 2019

@codecov

This comment has been minimized.

Copy link

commented Jul 26, 2019

Codecov Report

Merging #5849 into master will increase coverage by 0.03%.
The diff coverage is 92.92%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master   #5849      +/-   ##
=========================================
+ Coverage   93.67%   93.7%   +0.03%     
=========================================
  Files         153     153              
  Lines       10636   10708      +72     
=========================================
+ Hits         9963   10034      +71     
- Misses        673     674       +1
Impacted Files Coverage Δ
src/Adapters/Storage/Mongo/MongoCollection.js 97.43% <100%> (ø) ⬆️
src/Adapters/Storage/Mongo/MongoStorageAdapter.js 92.92% <100%> (+1.07%) ⬆️
src/Controllers/DatabaseController.js 94.81% <81.81%> (-0.27%) ⬇️
src/ParseServerRESTController.js 94.73% <90.47%> (-0.51%) ⬇️
...dapters/Storage/Postgres/PostgresStorageAdapter.js 96.87% <93.54%> (-0.03%) ⬇️
src/batch.js 90.38% <95.23%> (+0.64%) ⬆️
src/RestWrite.js 93.56% <0%> (-0.17%) ⬇️
src/Adapters/WebSocketServer/WSAdapter.js 100% <0%> (ø) ⬆️
... and 1 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d4fa62a...20cb761. Read the comment docs.

davimacedo added 10 commits Jul 26, 2019
@davimacedo

This comment has been minimized.

Copy link
Member Author

commented Jul 26, 2019

@dplewis sorry for flooding you with so many commits in this PR. It is actually working, but MongoDB only supports transactions when running version >4 in a wiredTiger replicaset. I am trying to figure out how to setup this environment in Travis. I will let you know then.

@dplewis

This comment has been minimized.

Copy link
Member

commented Jul 26, 2019

No problem take your time. I know this is a highly requested feature.

@davimacedo davimacedo force-pushed the back4app:batchTransaction branch from 5fa15c9 to dd214be Jul 29, 2019

@davimacedo davimacedo requested a review from dplewis Jul 29, 2019

};
let initialPromise = Promise.resolve();
if (req.body.transaction === true) {
initialPromise = req.config.database.createTransactionalSession();

This comment has been minimized.

Copy link
@dplewis

dplewis Jul 29, 2019

Member

Good job getting this one in. I can't wait to use it.

Can you add this to direct access?

https://github.com/parse-community/parse-server/blob/master/src/ParseServerRESTController.js

This comment has been minimized.

Copy link
@davimacedo

davimacedo Jul 31, 2019

Author Member

done

@davimacedo davimacedo requested a review from dplewis Jul 31, 2019

@dplewis
Copy link
Member

left a comment

LGTM!

@davimacedo davimacedo merged commit 8b97c13 into parse-community:master Jul 31, 2019

3 of 4 checks passed

codecov/patch 92.92% of diff hit (target 93.67%)
Details
Danger All good
Details
codecov/project 93.7% (+0.03%) compared to c704018
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.