diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-11-16 18:40:50 +0100 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-11-27 19:40:52 +0100 |
commit | 47e0652b4a98916d4a1d012fbec61afd73a30565 (patch) | |
tree | 8d400cce95b50d18921b30fea1d5d2d89b5da740 /server/controllers/api | |
parent | 41dbdb8acff3ac56187e8149eab0ff82e2377597 (diff) | |
download | PeerTube-47e0652b4a98916d4a1d012fbec61afd73a30565.tar.gz PeerTube-47e0652b4a98916d4a1d012fbec61afd73a30565.tar.zst PeerTube-47e0652b4a98916d4a1d012fbec61afd73a30565.zip |
Optimize account creation
Diffstat (limited to 'server/controllers/api')
-rw-r--r-- | server/controllers/api/users.ts | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/server/controllers/api/users.ts b/server/controllers/api/users.ts index 41ffb64cb..ac7c87517 100644 --- a/server/controllers/api/users.ts +++ b/server/controllers/api/users.ts | |||
@@ -70,7 +70,7 @@ usersRouter.post('/', | |||
70 | usersRouter.post('/register', | 70 | usersRouter.post('/register', |
71 | ensureUserRegistrationAllowed, | 71 | ensureUserRegistrationAllowed, |
72 | usersRegisterValidator, | 72 | usersRegisterValidator, |
73 | asyncMiddleware(registerUser) | 73 | asyncMiddleware(registerUserRetryWrapper) |
74 | ) | 74 | ) |
75 | 75 | ||
76 | usersRouter.put('/me', | 76 | usersRouter.put('/me', |
@@ -113,7 +113,7 @@ async function getUserVideos (req: express.Request, res: express.Response, next: | |||
113 | 113 | ||
114 | async function createUserRetryWrapper (req: express.Request, res: express.Response, next: express.NextFunction) { | 114 | async function createUserRetryWrapper (req: express.Request, res: express.Response, next: express.NextFunction) { |
115 | const options = { | 115 | const options = { |
116 | arguments: [ req, res ], | 116 | arguments: [ req ], |
117 | errorMessage: 'Cannot insert the user with many retries.' | 117 | errorMessage: 'Cannot insert the user with many retries.' |
118 | } | 118 | } |
119 | 119 | ||
@@ -123,7 +123,7 @@ async function createUserRetryWrapper (req: express.Request, res: express.Respon | |||
123 | return res.type('json').status(204).end() | 123 | return res.type('json').status(204).end() |
124 | } | 124 | } |
125 | 125 | ||
126 | async function createUser (req: express.Request, res: express.Response, next: express.NextFunction) { | 126 | async function createUser (req: express.Request) { |
127 | const body: UserCreate = req.body | 127 | const body: UserCreate = req.body |
128 | const user = db.User.build({ | 128 | const user = db.User.build({ |
129 | username: body.username, | 129 | username: body.username, |
@@ -139,7 +139,18 @@ async function createUser (req: express.Request, res: express.Response, next: ex | |||
139 | logger.info('User %s with its channel and account created.', body.username) | 139 | logger.info('User %s with its channel and account created.', body.username) |
140 | } | 140 | } |
141 | 141 | ||
142 | async function registerUser (req: express.Request, res: express.Response, next: express.NextFunction) { | 142 | async function registerUserRetryWrapper (req: express.Request, res: express.Response, next: express.NextFunction) { |
143 | const options = { | ||
144 | arguments: [ req ], | ||
145 | errorMessage: 'Cannot insert the user with many retries.' | ||
146 | } | ||
147 | |||
148 | await retryTransactionWrapper(registerUser, options) | ||
149 | |||
150 | return res.type('json').status(204).end() | ||
151 | } | ||
152 | |||
153 | async function registerUser (req: express.Request) { | ||
143 | const body: UserCreate = req.body | 154 | const body: UserCreate = req.body |
144 | 155 | ||
145 | const user = db.User.build({ | 156 | const user = db.User.build({ |
@@ -152,7 +163,8 @@ async function registerUser (req: express.Request, res: express.Response, next: | |||
152 | }) | 163 | }) |
153 | 164 | ||
154 | await createUserAccountAndChannel(user) | 165 | await createUserAccountAndChannel(user) |
155 | return res.type('json').status(204).end() | 166 | |
167 | logger.info('User %s with its channel and account registered.', body.username) | ||
156 | } | 168 | } |
157 | 169 | ||
158 | async function getUserInformation (req: express.Request, res: express.Response, next: express.NextFunction) { | 170 | async function getUserInformation (req: express.Request, res: express.Response, next: express.NextFunction) { |