From 7b1295884861b222e441f431089ea3a6d99fd569 Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Thu, 10 Jan 2013 11:45:46 +0100 Subject: Started to fragment cache gs_parameter views. --- Gemfile | 3 +++ Gemfile.lock | 3 +++ app/controllers/gs_parameters_controller.rb | 1 + app/views/gs_parameters/_index_core.html.haml | 28 +++++++++++---------- app/views/gs_parameters/index.html.haml | 24 +++++++++--------- app/views/gs_parameters/show.html.haml | 35 ++++++++++++++------------- config/environments/development.rb | 2 +- 7 files changed, 53 insertions(+), 43 deletions(-) diff --git a/Gemfile b/Gemfile index 54ab3d4..0b9ba7a 100644 --- a/Gemfile +++ b/Gemfile @@ -14,7 +14,10 @@ gem 'state_machine' gem 'acts_as_list' +# Useful Rails 4 stuff +# gem 'strong_parameters' +gem 'cache_digests' # Nicer console output: gem "hirb" diff --git a/Gemfile.lock b/Gemfile.lock index 8c13c02..bafe83f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -34,6 +34,8 @@ GEM bcrypt-ruby (3.0.1) breadcrumbs_on_rails (2.2.0) builder (3.0.0) + cache_digests (0.2.0) + actionpack (>= 3.2) cancan (1.6.7) carrierwave (0.5.8) activesupport (~> 3.0) @@ -176,6 +178,7 @@ DEPENDENCIES acts_as_list bcrypt-ruby breadcrumbs_on_rails + cache_digests cancan carrierwave coffee-rails (~> 3.2.1) diff --git a/app/controllers/gs_parameters_controller.rb b/app/controllers/gs_parameters_controller.rb index a35e373..a7813dc 100644 --- a/app/controllers/gs_parameters_controller.rb +++ b/app/controllers/gs_parameters_controller.rb @@ -1,5 +1,6 @@ class GsParametersController < ApplicationController def index + @ps_parameters_unordered = GsParameter.scoped @gs_parameters = GsParameter.order([:section, :name]) @sections = @gs_parameters.pluck(:section).uniq.sort end diff --git a/app/views/gs_parameters/_index_core.html.haml b/app/views/gs_parameters/_index_core.html.haml index 57fd85f..ece3922 100644 --- a/app/views/gs_parameters/_index_core.html.haml +++ b/app/views/gs_parameters/_index_core.html.haml @@ -1,14 +1,16 @@ -%tr - %th= t('gs_parameters.index.name') - - if !@sections - %th= t('gs_parameters.index.section') - %th= t('gs_parameters.index.value') - -- reset_cycle -- for gs_parameter in gs_parameters - %tr{:class => cycle('odd', 'even')} - %td= gs_parameter.name +- cache([gs_parameters.first.section, gs_parameters.reorder(:updated_at).last, gs_parameters.pluck(:id)]) do + %tr + %th= t('gs_parameters.index.name') + 'asd' - if !@sections - %td= gs_parameter.section - %td= gs_parameter.value - =render :partial => 'shared/index_view_edit_destroy_part', :locals => {:child => gs_parameter} \ No newline at end of file + %th= t('gs_parameters.index.section') + %th= t('gs_parameters.index.value') + + - reset_cycle + - for gs_parameter in gs_parameters + - cache(gs_parameter) do + %tr{:class => cycle('odd', 'even')} + %td= gs_parameter.name + - if !@sections + %td= gs_parameter.section + %td= gs_parameter.value + =render :partial => 'shared/index_view_edit_destroy_part', :locals => {:child => gs_parameter} \ No newline at end of file diff --git a/app/views/gs_parameters/index.html.haml b/app/views/gs_parameters/index.html.haml index 753e64b..51957b6 100644 --- a/app/views/gs_parameters/index.html.haml +++ b/app/views/gs_parameters/index.html.haml @@ -1,15 +1,15 @@ - title t("gs_parameters.index.page_title") - if @gs_parameters && @gs_parameters.count > 0 - - if @sections - %table - - @sections.each do |section| - %tr - %td{:colspan => 3} - %h3= section - = render "index_core", :gs_parameters => @gs_parameters.where(:section => section) - - else - %table - = render "index_core", :gs_parameters => @gs_parameters - -= render :partial => 'shared/create_link', :locals => {:child_class => GsParameter} \ No newline at end of file + - cache([@ps_parameters_unordered.order(:updated_at).last, @ps_parameters_unordered.pluck(:id)]) do + - if @sections + %table + - @sections.each do |section| + %tr + %td{:colspan => 3} + %h3= section + / Template Dependency: gs_parameters/index_core + = render "index_core", :gs_parameters => @gs_parameters.where(:section => section) + - else + %table + = render "index_core", :gs_parameters => @gs_parameters diff --git a/app/views/gs_parameters/show.html.haml b/app/views/gs_parameters/show.html.haml index 185641d..7919f8c 100644 --- a/app/views/gs_parameters/show.html.haml +++ b/app/views/gs_parameters/show.html.haml @@ -1,19 +1,20 @@ -- title t("gs_parameters.show.page_title") +- cache(@gs_parameter) do + - title t("gs_parameters.show.page_title") -%p - %strong= t('gs_parameters.show.name') + ":" - = @gs_parameter.name -%p - %strong= t('gs_parameters.show.section') + ":" - = @gs_parameter.section -%p - %strong= t('gs_parameters.show.value') + ":" - = @gs_parameter.value -%p - %strong= t('gs_parameters.show.class_type') + ":" - = @gs_parameter.class_type -%p - %strong= t('gs_parameters.show.description') + ":" - = @gs_parameter.description + %p + %strong= t('gs_parameters.show.name') + ":" + = @gs_parameter.name + %p + %strong= t('gs_parameters.show.section') + ":" + = @gs_parameter.section + %p + %strong= t('gs_parameters.show.value') + ":" + = @gs_parameter.value + %p + %strong= t('gs_parameters.show.class_type') + ":" + = @gs_parameter.class_type + %p + %strong= t('gs_parameters.show.description') + ":" + = @gs_parameter.description -= render :partial => 'shared/show_edit_destroy_part', :locals => { :child => @gs_parameter } \ No newline at end of file + = render :partial => 'shared/show_edit_destroy_part', :locals => { :child => @gs_parameter } \ No newline at end of file diff --git a/config/environments/development.rb b/config/environments/development.rb index bd34e4f..5130681 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -11,7 +11,7 @@ Gemeinschaft42c::Application.configure do # Show full error reports and disable caching config.consider_all_requests_local = true - config.action_controller.perform_caching = false + config.action_controller.perform_caching = true # Don't care if the mailer can't send config.action_mailer.raise_delivery_errors = false -- cgit v1.2.3 From 2b57fadfebf7f7df6a589ab089eec522413e8390 Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Thu, 10 Jan 2013 12:29:07 +0100 Subject: Added fragment caching to gs_parameters. --- app/views/gs_parameters/_index_core.html.haml | 2 +- app/views/gs_parameters/index.html.haml | 2 +- config/environments/development.rb | 3 +++ 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/app/views/gs_parameters/_index_core.html.haml b/app/views/gs_parameters/_index_core.html.haml index ece3922..0c36560 100644 --- a/app/views/gs_parameters/_index_core.html.haml +++ b/app/views/gs_parameters/_index_core.html.haml @@ -1,6 +1,6 @@ - cache([gs_parameters.first.section, gs_parameters.reorder(:updated_at).last, gs_parameters.pluck(:id)]) do %tr - %th= t('gs_parameters.index.name') + 'asd' + %th= t('gs_parameters.index.name') - if !@sections %th= t('gs_parameters.index.section') %th= t('gs_parameters.index.value') diff --git a/app/views/gs_parameters/index.html.haml b/app/views/gs_parameters/index.html.haml index 51957b6..3c16806 100644 --- a/app/views/gs_parameters/index.html.haml +++ b/app/views/gs_parameters/index.html.haml @@ -8,7 +8,7 @@ %tr %td{:colspan => 3} %h3= section - / Template Dependency: gs_parameters/index_core + -# Template Dependency: gs_parameters/_index_core = render "index_core", :gs_parameters => @gs_parameters.where(:section => section) - else %table diff --git a/config/environments/development.rb b/config/environments/development.rb index 5130681..5076f48 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -11,7 +11,10 @@ Gemeinschaft42c::Application.configure do # Show full error reports and disable caching config.consider_all_requests_local = true + + # Enable caching for development config.action_controller.perform_caching = true + CacheDigests::TemplateDigestor.cache = ActiveSupport::Cache::NullStore.new # Don't care if the mailer can't send config.action_mailer.raise_delivery_errors = false -- cgit v1.2.3