1
0
Fork 0
mirror of https://github.com/Chocobozzz/PeerTube.git synced 2025-10-05 19:42:24 +02:00

Optimize account creation

This commit is contained in:
Chocobozzz 2017-11-16 18:40:50 +01:00
parent 41dbdb8acf
commit 47e0652b4a
No known key found for this signature in database
GPG key ID: 583A612D890159BE
8 changed files with 44 additions and 26 deletions

View file

@ -70,7 +70,7 @@ usersRouter.post('/',
usersRouter.post('/register',
ensureUserRegistrationAllowed,
usersRegisterValidator,
asyncMiddleware(registerUser)
asyncMiddleware(registerUserRetryWrapper)
)
usersRouter.put('/me',
@ -113,7 +113,7 @@ async function getUserVideos (req: express.Request, res: express.Response, next:
async function createUserRetryWrapper (req: express.Request, res: express.Response, next: express.NextFunction) {
const options = {
arguments: [ req, res ],
arguments: [ req ],
errorMessage: 'Cannot insert the user with many retries.'
}
@ -123,7 +123,7 @@ async function createUserRetryWrapper (req: express.Request, res: express.Respon
return res.type('json').status(204).end()
}
async function createUser (req: express.Request, res: express.Response, next: express.NextFunction) {
async function createUser (req: express.Request) {
const body: UserCreate = req.body
const user = db.User.build({
username: body.username,
@ -139,7 +139,18 @@ async function createUser (req: express.Request, res: express.Response, next: ex
logger.info('User %s with its channel and account created.', body.username)
}
async function registerUser (req: express.Request, res: express.Response, next: express.NextFunction) {
async function registerUserRetryWrapper (req: express.Request, res: express.Response, next: express.NextFunction) {
const options = {
arguments: [ req ],
errorMessage: 'Cannot insert the user with many retries.'
}
await retryTransactionWrapper(registerUser, options)
return res.type('json').status(204).end()
}
async function registerUser (req: express.Request) {
const body: UserCreate = req.body
const user = db.User.build({
@ -152,7 +163,8 @@ async function registerUser (req: express.Request, res: express.Response, next:
})
await createUserAccountAndChannel(user)
return res.type('json').status(204).end()
logger.info('User %s with its channel and account registered.', body.username)
}
async function getUserInformation (req: express.Request, res: express.Response, next: express.NextFunction) {