1
0
Fork 0

Speedup peertube startup

This commit is contained in:
Chocobozzz 2018-11-19 15:21:09 +01:00
parent 361805c48b
commit 0b2f03d371
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
4 changed files with 47 additions and 27 deletions

View File

@ -204,9 +204,11 @@ async function startApplication () {
// Email initialization // Email initialization
Emailer.Instance.init() Emailer.Instance.init()
await Emailer.Instance.checkConnectionOrDie()
await JobQueue.Instance.init() await Promise.all([
Emailer.Instance.checkConnectionOrDie(),
JobQueue.Instance.init()
])
// Caches initializations // Caches initializations
VideosPreviewCache.Instance.init(CONFIG.CACHE.PREVIEWS.SIZE, CACHE.PREVIEWS.MAX_AGE) VideosPreviewCache.Instance.init(CONFIG.CACHE.PREVIEWS.SIZE, CACHE.PREVIEWS.MAX_AGE)

View File

@ -119,25 +119,27 @@ export {
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
async function checkPostgresExtensions () { async function checkPostgresExtensions () {
const extensions = [ const promises = [
'pg_trgm', checkPostgresExtension('pg_trgm'),
'unaccent' checkPostgresExtension('unaccent')
] ]
for (const extension of extensions) { return Promise.all(promises)
const query = `SELECT true AS enabled FROM pg_available_extensions WHERE name = '${extension}' AND installed_version IS NOT NULL;` }
const [ res ] = await sequelizeTypescript.query(query, { raw: true })
if (!res || res.length === 0 || res[ 0 ][ 'enabled' ] !== true) { async function checkPostgresExtension (extension: string) {
// Try to create the extension ourself const query = `SELECT true AS enabled FROM pg_available_extensions WHERE name = '${extension}' AND installed_version IS NOT NULL;`
try { const [ res ] = await sequelizeTypescript.query(query, { raw: true })
await sequelizeTypescript.query(`CREATE EXTENSION ${extension};`, { raw: true })
} catch { if (!res || res.length === 0 || res[ 0 ][ 'enabled' ] !== true) {
const errorMessage = `You need to enable ${extension} extension in PostgreSQL. ` + // Try to create the extension ourself
`You can do so by running 'CREATE EXTENSION ${extension};' as a PostgreSQL super user in ${CONFIG.DATABASE.DBNAME} database.` try {
throw new Error(errorMessage) await sequelizeTypescript.query(`CREATE EXTENSION ${extension};`, { raw: true })
}
} catch {
const errorMessage = `You need to enable ${extension} extension in PostgreSQL. ` +
`You can do so by running 'CREATE EXTENSION ${extension};' as a PostgreSQL super user in ${CONFIG.DATABASE.DBNAME} database.`
throw new Error(errorMessage)
} }
} }
} }

View File

@ -12,12 +12,21 @@ import { remove, ensureDir } from 'fs-extra'
async function installApplication () { async function installApplication () {
try { try {
await sequelizeTypescript.sync() await Promise.all([
await removeCacheDirectories() // Database related
await createDirectoriesIfNotExist() sequelizeTypescript.sync()
await createApplicationIfNotExist() .then(() => {
await createOAuthClientIfNotExist() return Promise.all([
await createOAuthAdminIfNotExist() createApplicationIfNotExist(),
createOAuthClientIfNotExist(),
createOAuthAdminIfNotExist()
])
}),
// Directories
removeCacheDirectories()
.then(() => createDirectoriesIfNotExist())
])
} catch (err) { } catch (err) {
logger.error('Cannot install application.', { err }) logger.error('Cannot install application.', { err })
process.exit(-1) process.exit(-1)

View File

@ -17,8 +17,10 @@ async function createUserAccountAndChannel (userToCreate: UserModel, validateUse
validate: validateUser validate: validateUser
} }
const userCreated = await userToCreate.save(userOptions) const [ userCreated, accountCreated ] = await Promise.all([
const accountCreated = await createLocalAccountWithoutKeys(userToCreate.username, userToCreate.id, null, t) userToCreate.save(userOptions),
createLocalAccountWithoutKeys(userToCreate.username, userToCreate.id, null, t)
])
userCreated.Account = accountCreated userCreated.Account = accountCreated
let channelName = userCreated.username + '_channel' let channelName = userCreated.username + '_channel'
@ -37,8 +39,13 @@ async function createUserAccountAndChannel (userToCreate: UserModel, validateUse
return { user: userCreated, account: accountCreated, videoChannel } return { user: userCreated, account: accountCreated, videoChannel }
}) })
account.Actor = await setAsyncActorKeys(account.Actor) const [ accountKeys, channelKeys ] = await Promise.all([
videoChannel.Actor = await setAsyncActorKeys(videoChannel.Actor) setAsyncActorKeys(account.Actor),
setAsyncActorKeys(videoChannel.Actor)
])
account.Actor = accountKeys
videoChannel.Actor = channelKeys
return { user, account, videoChannel } as { user: UserModel, account: AccountModel, videoChannel: VideoChannelModel } return { user, account, videoChannel } as { user: UserModel, account: AccountModel, videoChannel: VideoChannelModel }
} }