From 850b042cab7a8c202cffb712f865598329e2365d Mon Sep 17 00:00:00 2001 From: Sam Date: Thu, 11 Apr 2013 16:24:08 +1000 Subject: [PATCH] introduce rack:cache as a default, so users don't need to configure apache or nginx under rack cache we are able to serve 620reqs a second per thin (on my machine) before it 12 (on my machine) reorganised so mini profilers can be cleanly disabled from config file added caching for categories index move production.rb to production.sample.rb --- Gemfile | 8 ++++-- Gemfile.lock | 7 +++++- app/controllers/application_controller.rb | 2 +- app/controllers/categories_controller.rb | 1 + .../common/_discourse_javascript.html.erb | 20 ++++----------- .../common/_discourse_stylesheet.html.erb | 18 ++++++------- app/views/layouts/no_js.html.erb | 18 +++---------- config/application.rb | 8 +++++- config/environments/development.rb | 6 ++--- .../{production.rb => production.sample.rb} | 25 +++++++++++++++---- config/environments/profile.rb | 14 ++++++----- .../{mini_profiler.rb => 06-mini_profiler.rb} | 6 +++++ ...silencers.rb => 07-backtrace_silencers.rb} | 0 config/initializers/99-rack-cache.rb | 11 ++++++++ lib/current_user.rb | 6 +++++ lib/discourse_redis.rb | 14 ++++++++--- 16 files changed, 100 insertions(+), 64 deletions(-) rename config/environments/{production.rb => production.sample.rb} (62%) rename config/initializers/{mini_profiler.rb => 06-mini_profiler.rb} (92%) rename config/initializers/{backtrace_silencers.rb => 07-backtrace_silencers.rb} (100%) create mode 100644 config/initializers/99-rack-cache.rb diff --git a/Gemfile b/Gemfile index 92aeefd9503..ef02bd1b50e 100644 --- a/Gemfile +++ b/Gemfile @@ -112,8 +112,12 @@ gem 'fast_blank' #, github: "SamSaffron/fast_blank" # IMPORTANT: mini profiler monkey patches, so it better be required last # If you want to amend mini profiler to do the monkey patches in the railstie -# we are open to it. -gem 'rack-mini-profiler' #, git: 'git://github.com/SamSaffron/MiniProfiler' +# we are open to it. by deferring require to the initializer we can configure disourse installs without it +gem 'rack-mini-profiler', require: false # require: false #, git: 'git://github.com/SamSaffron/MiniProfiler' + +# used for caching, optional +gem 'redis-rack-cache', require: false +gem 'rack-cache', require: false # perftools only works on 1.9 atm group :profile do diff --git a/Gemfile.lock b/Gemfile.lock index b9a7c112757..340090ab075 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -319,7 +319,7 @@ GEM rack (1.4.5) rack-cache (1.2) rack (>= 0.4) - rack-mini-profiler (0.1.25) + rack-mini-profiler (0.1.26) rack (>= 1.1.3) rack-openid (1.3.1) rack (>= 1.1.0) @@ -367,6 +367,9 @@ GEM redis-rack (1.4.2) rack (~> 1.4.1) redis-store (~> 1.1.0) + redis-rack-cache (1.2.1) + rack-cache (~> 1.2) + redis-store (~> 1.1.0) redis-rails (3.2.3) redis-actionpack (~> 3.2.3) redis-activesupport (~> 3.2.3) @@ -514,6 +517,7 @@ DEPENDENCIES openid-redis-store pg pry-rails + rack-cache rack-mini-profiler rails rails_multisite! @@ -522,6 +526,7 @@ DEPENDENCIES rb-inotify (~> 0.8.8) redcarpet redis + redis-rack-cache redis-rails rest-client rinku diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 0b423b527d4..e0e744af2a0 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -140,7 +140,7 @@ class ApplicationController < ActionController::Base def can_cache_content? # Don't cache unless we're in production mode - return false unless Rails.env.production? + return false unless Rails.env.production? || Rails.env == "profile" # Don't cache logged in users return false if current_user.present? diff --git a/app/controllers/categories_controller.rb b/app/controllers/categories_controller.rb index ca98cbf72d5..1c6a62c0e85 100644 --- a/app/controllers/categories_controller.rb +++ b/app/controllers/categories_controller.rb @@ -6,6 +6,7 @@ class CategoriesController < ApplicationController def index list = CategoryList.new(current_user) + discourse_expires_in 1.minute render_serialized(list, CategoryListSerializer) end diff --git a/app/views/common/_discourse_javascript.html.erb b/app/views/common/_discourse_javascript.html.erb index c0c6ead0c4d..72b8f05d4ca 100644 --- a/app/views/common/_discourse_javascript.html.erb +++ b/app/views/common/_discourse_javascript.html.erb @@ -16,21 +16,11 @@ <%# load the selected locale before any other scripts %> <%= javascript_include_tag "locales/#{I18n.locale}" %> - -<%- if mini_profiler_enabled? %> - <%- Rack::MiniProfiler.step "application" do %> - <%= javascript_include_tag "application" %> - <%-end%> - - <%- Rack::MiniProfiler.step "admin" do %> - <%= javascript_include_tag "admin"%> - <%-end%> -<%- else %> - <%= javascript_include_tag "application" %> - <%- if admin? %> - <%= javascript_include_tag "admin"%> - <%- end %> -<%- end%> +<%= javascript_include_tag "application" %> +<%= javascript_include_tag "admin"%> +<%- if admin? %> + <%= javascript_include_tag "admin"%> +<%- end %>