made project page load faaaaaaster

This commit is contained in:
Henry Oswald 2014-04-08 17:59:29 +01:00
parent 88ba45b9dc
commit c0780f5a67

View file

@ -75,51 +75,46 @@ module.exports =
timer.done() timer.done()
loadEditor: (req, res)-> loadEditor: (req, res)->
timer = new metrics.Timer("load-editor") timer = new metrics.Timer("load-editor")
if !Settings.editorIsOpen if !Settings.editorIsOpen
res.render("general/closed", {title:"updating site"}) return res.render("general/closed", {title:"updating site"})
else
if req.session.user? user_id = if req.session.user? then req.session.user._id else 'openUser'
user_id = req.session.user._id
else
user_id = 'openUser'
project_id = req.params.Project_id project_id = req.params.Project_id
Project.findPopulatedById project_id, (err, project)->
User.findById user_id, (err, user)-> async.parallel {
project: (cb)->
Project.findPopulatedById project_id, cb
user: (cb)->
User.findById user_id, cb
subscription: (cb)->
SubscriptionLocator.getUsersSubscription user_id, cb
}, (err, results)->
if err?
return res.send 500
project = results.project
user = results.user
subscription = results.subscription
if user_id == 'openUser' if user_id == 'openUser'
anonymous = true anonymous = true
user = user = defaultSettingsForAnonymousUser(user_id)
id : user_id
ace:
mode:'none'
theme:'textmate'
fontSize: '12'
autoComplete: true
spellCheckLanguage: ""
pdfViewer: ""
subscription:
freeTrial:
allowed: true
featureSwitches:
dropbox: false
trackChanges: false
else else
anonymous = false anonymous = false
SubscriptionLocator.getUsersSubscription user?._id, (err, subscription)->
SecurityManager.userCanAccessProject user, project, (canAccess, privilegeLevel)-> SecurityManager.userCanAccessProject user, project, (canAccess, privilegeLevel)->
allowedFreeTrial = true if !canAccess
return res.send 401
if subscription? and subscription.freeTrial? and subscription.freeTrial.expiresAt? if subscription? and subscription.freeTrial? and subscription.freeTrial.expiresAt?
allowedFreeTrial = !!subscription.freeTrial.allowed allowedFreeTrial = !!subscription.freeTrial.allowed || true
if canAccess
timer.done()
res.render 'project/editor', res.render 'project/editor',
title: project.name title: project.name
priority_title: true priority_title: true
bodyClasses: ["editor"] bodyClasses: ["editor"]
project : project project : project
#owner : project.owner_ref
userObject : JSON.stringify({ userObject : JSON.stringify({
id : user.id id : user.id
email : user.email email : user.email
@ -149,11 +144,24 @@ module.exports =
chatUrl: Settings.apis.chat.url chatUrl: Settings.apis.chat.url
anonymous: anonymous anonymous: anonymous
languages: Settings.languages languages: Settings.languages
else timer.done()
res.send 401
defaultSettingsForAnonymousUser = ->
id : user_id
ace:
mode:'none'
theme:'textmate'
fontSize: '12'
autoComplete: true
spellCheckLanguage: ""
pdfViewer: ""
subscription:
freeTrial:
allowed: true
featureSwitches:
dropbox: false
trackChanges: false