From 47e0652b4a98916d4a1d012fbec61afd73a30565 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 16 Nov 2017 18:40:50 +0100 Subject: Optimize account creation --- server/lib/user.ts | 22 ++++++++++++++-------- server/lib/video-channel.ts | 4 +--- 2 files changed, 15 insertions(+), 11 deletions(-) (limited to 'server/lib') diff --git a/server/lib/user.ts b/server/lib/user.ts index 9884e566f..2d7b36b4f 100644 --- a/server/lib/user.ts +++ b/server/lib/user.ts @@ -5,16 +5,17 @@ import { database as db } from '../initializers' import { CONFIG } from '../initializers/constants' import { UserInstance } from '../models' import { createVideoChannel } from './video-channel' +import { logger } from '../helpers/logger' async function createUserAccountAndChannel (user: UserInstance, validateUser = true) { - const res = await db.sequelize.transaction(async t => { + const { account, videoChannel } = await db.sequelize.transaction(async t => { const userOptions = { transaction: t, validate: validateUser } const userCreated = await user.save(userOptions) - const accountCreated = await createLocalAccount(user.username, user.id, null, t) + const accountCreated = await createLocalAccountWithoutKeys(user.username, user.id, null, t) const videoChannelName = `Default ${userCreated.username} channel` const videoChannelInfo = { @@ -25,18 +26,23 @@ async function createUserAccountAndChannel (user: UserInstance, validateUser = t return { account: accountCreated, videoChannel } }) - return res + // Set account keys, this could be long so process after the account creation and do not block the client + const { publicKey, privateKey } = await createPrivateAndPublicKeys() + account.set('publicKey', publicKey) + account.set('privateKey', privateKey) + account.save().catch(err => logger.error('Cannot set public/private keys of local account %d.', account.id, err)) + + return { account, videoChannel } } -async function createLocalAccount (name: string, userId: number, applicationId: number, t: Sequelize.Transaction) { - const { publicKey, privateKey } = await createPrivateAndPublicKeys() +async function createLocalAccountWithoutKeys (name: string, userId: number, applicationId: number, t: Sequelize.Transaction) { const url = getActivityPubUrl('account', name) const accountInstance = db.Account.build({ name, url, - publicKey, - privateKey, + publicKey: null, + privateKey: null, followersCount: 0, followingCount: 0, inboxUrl: url + '/inbox', @@ -56,5 +62,5 @@ async function createLocalAccount (name: string, userId: number, applicationId: export { createUserAccountAndChannel, - createLocalAccount + createLocalAccountWithoutKeys } diff --git a/server/lib/video-channel.ts b/server/lib/video-channel.ts index e69ec062f..6f9ae2d95 100644 --- a/server/lib/video-channel.ts +++ b/server/lib/video-channel.ts @@ -25,9 +25,7 @@ async function createVideoChannel (videoChannelInfo: VideoChannelCreate, account // Do not forget to add Account information to the created video channel videoChannelCreated.Account = account - await sendCreateVideoChannel(videoChannelCreated, t) - await shareVideoChannelByServer(videoChannelCreated, t) - + // No need to seed this empty video channel to followers return videoChannelCreated } -- cgit v1.2.3