aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-11-19 15:21:09 +0100
committerChocobozzz <me@florianbigard.com>2018-11-19 15:21:09 +0100
commit0b2f03d3712f438f67eccf86b67acd047284f9b4 (patch)
treeb6ae2ca2405d6a915e6be34e1d3c4e04312f6f03
parent361805c48b14c5402c9984485c67c45a1a3113cc (diff)
downloadPeerTube-0b2f03d3712f438f67eccf86b67acd047284f9b4.tar.gz
PeerTube-0b2f03d3712f438f67eccf86b67acd047284f9b4.tar.zst
PeerTube-0b2f03d3712f438f67eccf86b67acd047284f9b4.zip
Speedup peertube startup
-rw-r--r--server.ts6
-rw-r--r--server/initializers/database.ts32
-rw-r--r--server/initializers/installer.ts21
-rw-r--r--server/lib/user.ts15
4 files changed, 47 insertions, 27 deletions
diff --git a/server.ts b/server.ts
index f3514cf9c..3025a6fd7 100644
--- a/server.ts
+++ b/server.ts
@@ -204,9 +204,11 @@ async function startApplication () {
204 204
205 // Email initialization 205 // Email initialization
206 Emailer.Instance.init() 206 Emailer.Instance.init()
207 await Emailer.Instance.checkConnectionOrDie()
208 207
209 await JobQueue.Instance.init() 208 await Promise.all([
209 Emailer.Instance.checkConnectionOrDie(),
210 JobQueue.Instance.init()
211 ])
210 212
211 // Caches initializations 213 // Caches initializations
212 VideosPreviewCache.Instance.init(CONFIG.CACHE.PREVIEWS.SIZE, CACHE.PREVIEWS.MAX_AGE) 214 VideosPreviewCache.Instance.init(CONFIG.CACHE.PREVIEWS.SIZE, CACHE.PREVIEWS.MAX_AGE)
diff --git a/server/initializers/database.ts b/server/initializers/database.ts
index dd5b9bf67..40cd659ab 100644
--- a/server/initializers/database.ts
+++ b/server/initializers/database.ts
@@ -119,25 +119,27 @@ export {
119// --------------------------------------------------------------------------- 119// ---------------------------------------------------------------------------
120 120
121async function checkPostgresExtensions () { 121async function checkPostgresExtensions () {
122 const extensions = [ 122 const promises = [
123 'pg_trgm', 123 checkPostgresExtension('pg_trgm'),
124 'unaccent' 124 checkPostgresExtension('unaccent')
125 ] 125 ]
126 126
127 for (const extension of extensions) { 127 return Promise.all(promises)
128 const query = `SELECT true AS enabled FROM pg_available_extensions WHERE name = '${extension}' AND installed_version IS NOT NULL;` 128}
129 const [ res ] = await sequelizeTypescript.query(query, { raw: true }) 129
130async function checkPostgresExtension (extension: string) {
131 const query = `SELECT true AS enabled FROM pg_available_extensions WHERE name = '${extension}' AND installed_version IS NOT NULL;`
132 const [ res ] = await sequelizeTypescript.query(query, { raw: true })
130 133
131 if (!res || res.length === 0 || res[ 0 ][ 'enabled' ] !== true) { 134 if (!res || res.length === 0 || res[ 0 ][ 'enabled' ] !== true) {
132 // Try to create the extension ourself 135 // Try to create the extension ourself
133 try { 136 try {
134 await sequelizeTypescript.query(`CREATE EXTENSION ${extension};`, { raw: true }) 137 await sequelizeTypescript.query(`CREATE EXTENSION ${extension};`, { raw: true })
135 138
136 } catch { 139 } catch {
137 const errorMessage = `You need to enable ${extension} extension in PostgreSQL. ` + 140 const errorMessage = `You need to enable ${extension} extension in PostgreSQL. ` +
138 `You can do so by running 'CREATE EXTENSION ${extension};' as a PostgreSQL super user in ${CONFIG.DATABASE.DBNAME} database.` 141 `You can do so by running 'CREATE EXTENSION ${extension};' as a PostgreSQL super user in ${CONFIG.DATABASE.DBNAME} database.`
139 throw new Error(errorMessage) 142 throw new Error(errorMessage)
140 }
141 } 143 }
142 } 144 }
143} 145}
diff --git a/server/initializers/installer.ts b/server/initializers/installer.ts
index c952ad46c..b9a9da183 100644
--- a/server/initializers/installer.ts
+++ b/server/initializers/installer.ts
@@ -12,12 +12,21 @@ import { remove, ensureDir } from 'fs-extra'
12 12
13async function installApplication () { 13async function installApplication () {
14 try { 14 try {
15 await sequelizeTypescript.sync() 15 await Promise.all([
16 await removeCacheDirectories() 16 // Database related
17 await createDirectoriesIfNotExist() 17 sequelizeTypescript.sync()
18 await createApplicationIfNotExist() 18 .then(() => {
19 await createOAuthClientIfNotExist() 19 return Promise.all([
20 await createOAuthAdminIfNotExist() 20 createApplicationIfNotExist(),
21 createOAuthClientIfNotExist(),
22 createOAuthAdminIfNotExist()
23 ])
24 }),
25
26 // Directories
27 removeCacheDirectories()
28 .then(() => createDirectoriesIfNotExist())
29 ])
21 } catch (err) { 30 } catch (err) {
22 logger.error('Cannot install application.', { err }) 31 logger.error('Cannot install application.', { err })
23 process.exit(-1) 32 process.exit(-1)
diff --git a/server/lib/user.ts b/server/lib/user.ts
index db29469eb..acb883e23 100644
--- a/server/lib/user.ts
+++ b/server/lib/user.ts
@@ -17,8 +17,10 @@ async function createUserAccountAndChannel (userToCreate: UserModel, validateUse
17 validate: validateUser 17 validate: validateUser
18 } 18 }
19 19
20 const userCreated = await userToCreate.save(userOptions) 20 const [ userCreated, accountCreated ] = await Promise.all([
21 const accountCreated = await createLocalAccountWithoutKeys(userToCreate.username, userToCreate.id, null, t) 21 userToCreate.save(userOptions),
22 createLocalAccountWithoutKeys(userToCreate.username, userToCreate.id, null, t)
23 ])
22 userCreated.Account = accountCreated 24 userCreated.Account = accountCreated
23 25
24 let channelName = userCreated.username + '_channel' 26 let channelName = userCreated.username + '_channel'
@@ -37,8 +39,13 @@ async function createUserAccountAndChannel (userToCreate: UserModel, validateUse
37 return { user: userCreated, account: accountCreated, videoChannel } 39 return { user: userCreated, account: accountCreated, videoChannel }
38 }) 40 })
39 41
40 account.Actor = await setAsyncActorKeys(account.Actor) 42 const [ accountKeys, channelKeys ] = await Promise.all([
41 videoChannel.Actor = await setAsyncActorKeys(videoChannel.Actor) 43 setAsyncActorKeys(account.Actor),
44 setAsyncActorKeys(videoChannel.Actor)
45 ])
46
47 account.Actor = accountKeys
48 videoChannel.Actor = channelKeys
42 49
43 return { user, account, videoChannel } as { user: UserModel, account: AccountModel, videoChannel: VideoChannelModel } 50 return { user, account, videoChannel } as { user: UserModel, account: AccountModel, videoChannel: VideoChannelModel }
44} 51}