// Email initialization
Emailer.Instance.init()
- await Emailer.Instance.checkConnectionOrDie()
- await JobQueue.Instance.init()
+ await Promise.all([
+ Emailer.Instance.checkConnectionOrDie(),
+ JobQueue.Instance.init()
+ ])
// Caches initializations
VideosPreviewCache.Instance.init(CONFIG.CACHE.PREVIEWS.SIZE, CACHE.PREVIEWS.MAX_AGE)
// ---------------------------------------------------------------------------
async function checkPostgresExtensions () {
- const extensions = [
- 'pg_trgm',
- 'unaccent'
+ const promises = [
+ checkPostgresExtension('pg_trgm'),
+ checkPostgresExtension('unaccent')
]
- for (const extension of extensions) {
- 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 })
+ return Promise.all(promises)
+}
+
+async function checkPostgresExtension (extension: string) {
+ 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) {
- // Try to create the extension ourself
- try {
- await sequelizeTypescript.query(`CREATE EXTENSION ${extension};`, { raw: true })
+ if (!res || res.length === 0 || res[ 0 ][ 'enabled' ] !== true) {
+ // Try to create the extension ourself
+ try {
+ 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)
- }
+ } 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)
}
}
}
async function installApplication () {
try {
- await sequelizeTypescript.sync()
- await removeCacheDirectories()
- await createDirectoriesIfNotExist()
- await createApplicationIfNotExist()
- await createOAuthClientIfNotExist()
- await createOAuthAdminIfNotExist()
+ await Promise.all([
+ // Database related
+ sequelizeTypescript.sync()
+ .then(() => {
+ return Promise.all([
+ createApplicationIfNotExist(),
+ createOAuthClientIfNotExist(),
+ createOAuthAdminIfNotExist()
+ ])
+ }),
+
+ // Directories
+ removeCacheDirectories()
+ .then(() => createDirectoriesIfNotExist())
+ ])
} catch (err) {
logger.error('Cannot install application.', { err })
process.exit(-1)
validate: validateUser
}
- const userCreated = await userToCreate.save(userOptions)
- const accountCreated = await createLocalAccountWithoutKeys(userToCreate.username, userToCreate.id, null, t)
+ const [ userCreated, accountCreated ] = await Promise.all([
+ userToCreate.save(userOptions),
+ createLocalAccountWithoutKeys(userToCreate.username, userToCreate.id, null, t)
+ ])
userCreated.Account = accountCreated
let channelName = userCreated.username + '_channel'
return { user: userCreated, account: accountCreated, videoChannel }
})
- account.Actor = await setAsyncActorKeys(account.Actor)
- videoChannel.Actor = await setAsyncActorKeys(videoChannel.Actor)
+ const [ accountKeys, channelKeys ] = await Promise.all([
+ setAsyncActorKeys(account.Actor),
+ setAsyncActorKeys(videoChannel.Actor)
+ ])
+
+ account.Actor = accountKeys
+ videoChannel.Actor = channelKeys
return { user, account, videoChannel } as { user: UserModel, account: AccountModel, videoChannel: VideoChannelModel }
}