Actually improve app backend performance

pull/574/merge
Thibaut Courouble 8 years ago
parent 2246c22820
commit b3d1c3865a

@ -21,27 +21,17 @@ class App < Sinatra::Application
set :cdn_origin, '' set :cdn_origin, ''
set :assets_prefix, 'assets' set :assets_prefix, 'assets'
set :assets_path, -> { File.join(public_folder, assets_prefix) } set :assets_path, File.join(public_folder, assets_prefix)
set :assets_manifest_path, -> { File.join(assets_path, 'manifest.json') } set :assets_manifest_path, File.join(assets_path, 'manifest.json')
set :assets_compile, %w(*.png docs.js docs.json application.js application.css application-dark.css) set :assets_compile, %w(*.png docs.js docs.json application.js application.css application-dark.css)
require 'yajl/json_gem' require 'yajl/json_gem'
set :docs_prefix, 'docs' set :docs_prefix, 'docs'
set :docs_origin, -> { File.join('', docs_prefix) } set :docs_origin, File.join('', docs_prefix)
set :docs_path, -> { File.join(public_folder, docs_prefix) } set :docs_path, File.join(public_folder, docs_prefix)
set :docs_manifest_path, -> { File.join(docs_path, 'docs.json') } set :docs_manifest_path, File.join(docs_path, 'docs.json')
set :default_docs, %w(css dom dom_events html http javascript) set :default_docs, %w(css dom dom_events html http javascript)
set :docs, -> { set :news_path, File.join(root, assets_prefix, 'javascripts', 'news.json')
Hash[JSON.parse(File.read(docs_manifest_path)).map! { |doc|
doc['full_name'] = doc['name'].dup
doc['full_name'] << " #{doc['version']}" if doc['version']
doc['slug_without_version'] = doc['slug'].split('~').first
[doc['slug'], doc]
}]
}
set :news_path, -> { File.join(root, assets_prefix, 'javascripts', 'news.json') }
set :news, -> { JSON.parse(File.read(news_path)) }
set :csp, false set :csp, false
@ -103,7 +93,30 @@ class App < Sinatra::Application
end end
configure :test do configure :test do
set :docs_manifest_path, -> { File.join(root, 'test', 'files', 'docs.json') } set :docs_manifest_path, File.join(root, 'test', 'files', 'docs.json')
end
def self.parse_docs
Hash[JSON.parse(File.read(docs_manifest_path)).map! { |doc|
doc['full_name'] = doc['name'].dup
doc['full_name'] << " #{doc['version']}" if doc['version']
doc['slug_without_version'] = doc['slug'].split('~').first
[doc['slug'], doc]
}]
end
def self.parse_news
JSON.parse(File.read(news_path))
end
configure :development, :test do
set :docs, -> { parse_docs }
set :news, -> { parse_news }
end
configure :production do
set :docs, parse_docs
set :news, parse_news
end end
helpers do helpers do

Loading…
Cancel
Save