mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Merge pull request #2370 from overleaf/bg-precompile-pug-templates
precompile pug templates GitOrigin-RevId: bf340f52b4d8c413056be2f3006a28a55548d783
This commit is contained in:
parent
4f9eb281b7
commit
82c2b0e8d4
2 changed files with 76 additions and 0 deletions
|
@ -29,6 +29,7 @@ const RedirectManager = require('./RedirectManager')
|
|||
const ProxyManager = require('./ProxyManager')
|
||||
const translations = require('translations-sharelatex').setup(Settings.i18n)
|
||||
const Modules = require('./Modules')
|
||||
const Views = require('./Views')
|
||||
|
||||
const ErrorController = require('../Features/Errors/ErrorController')
|
||||
const HttpErrorController = require('../Features/Errors/HttpErrorController')
|
||||
|
@ -168,6 +169,7 @@ expressLocals(webRouter, privateApiRouter, publicApiRouter)
|
|||
if (app.get('env') === 'production') {
|
||||
logger.info('Production Enviroment')
|
||||
app.enable('view cache')
|
||||
Views.precompileViews(app) // precompile templates
|
||||
}
|
||||
|
||||
webRouter.use(function(req, res, next) {
|
||||
|
|
74
services/web/app/src/infrastructure/Views.js
Normal file
74
services/web/app/src/infrastructure/Views.js
Normal file
|
@ -0,0 +1,74 @@
|
|||
const logger = require('logger-sharelatex')
|
||||
const pug = require('pug')
|
||||
|
||||
// List of view names found with
|
||||
//
|
||||
// git grep res.render | perl filter.pl | sort -u
|
||||
//
|
||||
// where filter.pl is the perl script below.
|
||||
//
|
||||
// #!/usr/bin/perl
|
||||
// while (<>) {print "'$1',\n" if /render\(\'(.*?)\'/;}
|
||||
|
||||
const viewList = [
|
||||
'admin/index',
|
||||
'admin/register',
|
||||
'beta_program/opt_in',
|
||||
'blog/blog_holder',
|
||||
'external/home/sl',
|
||||
'external/home/v2',
|
||||
'general/404',
|
||||
'general/500',
|
||||
'general/closed',
|
||||
'project/cannot-import-v1-project',
|
||||
'project/editor',
|
||||
'project/importing',
|
||||
'project/invite/not-valid',
|
||||
'project/invite/show',
|
||||
'project/list',
|
||||
'project/v2-import',
|
||||
'referal/bonus',
|
||||
'subscriptions/canceled_subscription',
|
||||
'subscriptions/dashboard',
|
||||
'subscriptions/new',
|
||||
'subscriptions/successful_subscription',
|
||||
'subscriptions/team/invite',
|
||||
'subscriptions/upgradeToAnnual',
|
||||
'sudo_mode/sudo_mode_prompt',
|
||||
'user/activate',
|
||||
'user/confirm_email',
|
||||
'user/login',
|
||||
'user/logout',
|
||||
'user_membership/index',
|
||||
'user_membership/new',
|
||||
'user/one_time_login',
|
||||
'user/passwordReset',
|
||||
'user/reconfirm',
|
||||
'user/register',
|
||||
'user/restricted',
|
||||
'user/sessions',
|
||||
'user/setPassword',
|
||||
'user/settings'
|
||||
]
|
||||
module.exports = {
|
||||
precompileViews(app) {
|
||||
let startTime = Date.now()
|
||||
let success = 0
|
||||
let failures = 0
|
||||
viewList.forEach(view => {
|
||||
try {
|
||||
let filename = app.get('views') + '/' + view + '.pug'
|
||||
pug.compileFile(filename, { cache: true })
|
||||
console.log('compiled', view)
|
||||
success++
|
||||
} catch (err) {
|
||||
console.log('error compiling', view, err)
|
||||
failures++
|
||||
}
|
||||
})
|
||||
logger.log(
|
||||
{ timeTaken: Date.now() - startTime, failures, success },
|
||||
'compiled templates'
|
||||
)
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue