From 95f3f634d271bf60b2acd08663d1a4ebd8659981 Mon Sep 17 00:00:00 2001 From: lakshmivyas Date: Sun, 15 Jun 2014 21:10:57 +0530 Subject: [PATCH] lml/ost#347: Cache user settings in session. --- app/controllers/application_controller.rb | 7 ++++++- app/controllers/user_settings_controller.rb | 5 ++--- app/views/layouts/application.html.erb | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index eaad8df1..6645ef83 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -24,7 +24,8 @@ class ApplicationController < ActionController::Base :present_user, :view_dir, :view_dir_from_string, - :enable_clock + :enable_clock, + :user_settings unless Ost::Application.config.consider_all_requests_local rescue_from Exception, :with => :rescue_from_exception @@ -247,4 +248,8 @@ def read_errors(object) @errors_object = object end + def user_settings + session[:user_settings] ||= UserSettings.for(present_user) + end + end diff --git a/app/controllers/user_settings_controller.rb b/app/controllers/user_settings_controller.rb index 2546db59..3971279d 100644 --- a/app/controllers/user_settings_controller.rb +++ b/app/controllers/user_settings_controller.rb @@ -5,11 +5,11 @@ class UserSettingsController < ApplicationController skip_before_filter :authenticate_user! def index - @settings = UserSettings.for(present_user) + @settings = user_settings end def update - @settings = UserSettings.for(present_user) + @settings = user_settings respond_to do |format| if @settings.update_attributes(params[:settings]) format.json { render json: {:success => true, message: 'Settings were successfully updated.'}} @@ -19,5 +19,4 @@ def update end end end - end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index f8a58c24..f56f14b8 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -45,7 +45,7 @@ <%= render :partial => 'layouts/common_head_includes' %> <% if current_user.present? %> - <% ost_user_settings = UserSettings.for(present_user) %> + <% ost_user_settings = user_settings %>