From c206a678bdb5ed797a12d4ad14b3a95145537d84 Mon Sep 17 00:00:00 2001 From: Alinson Santos Date: Thu, 6 Mar 2008 18:56:00 -0300 Subject: [PATCH] Reativando o cache nas folhas de estilo --- app/controllers/attachments_controller.rb | 4 +- app/controllers/courses_controller.rb | 13 ++--- app/controllers/events_controller.rb | 6 +-- app/controllers/news_controller.rb | 6 +-- app/controllers/stylesheets_controller.rb | 2 +- app/controllers/users_controller.rb | 4 +- app/controllers/wiki_controller.rb | 8 ++-- app/views/courses/_left_panel.html.haml | 5 +- app/views/courses/_right_panel.html.haml | 6 +-- app/views/courses/index.html.haml | 44 ++++++++--------- app/views/courses/show.html.haml | 43 +++++++++-------- app/views/events/index.html.haml | 58 +++++++++++------------ app/views/layouts/base.html.haml | 4 +- app/views/news/index.html.haml | 50 +++++++++---------- app/views/users/index.html.haml | 12 ++--- app/views/users/show.html.haml | 24 +++++----- app/views/wiki/show.html.haml | 15 +++--- config/environments/production.rb | 2 +- config/routes.rb | 4 +- db/schema.rb | 2 +- 20 files changed, 154 insertions(+), 158 deletions(-) diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index f938492..a617ddc 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -17,7 +17,7 @@ class AttachmentsController < ApplicationController # :redirect_to => { :controller => 'courses', :action => :show } before_filter :find_attachment, :except => [ :undelete ] - after_filter :cache_sweep, :only => [ :create, :update, :destroy ] + #after_filter :cache_sweep, :only => [ :create, :update, :destroy ] def show end @@ -100,6 +100,6 @@ class AttachmentsController < ApplicationController end def cache_sweep - expire_fragment(:controller => 'courses', :action => 'show') + expire_fragment(course_path(@course.id)) end end diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index e534b1d..ebc2420 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -16,12 +16,10 @@ class CoursesController < ApplicationController before_filter :require_admin, :only => [ :new, :create, :edit, :update, :destroy ] before_filter :require_login, :only => [ :enroll, :unenroll ] before_filter :find_course, :except => [ :index ] - after_filter :cache_sweep, :only => [ :create, :update, :destroy ] + #after_filter :cache_sweep, :only => [ :create, :update, :destroy ] def index - @courses = Course.find(:all, - :order => 'period asc, full_name asc', - :conditions => (logged_in? and !@current_user.courses.empty? ? [ 'id not in (?)', @current_user.courses] : '')) + @courses = Course.find(:all, :order => 'period asc, full_name asc') respond_to do |format| format.html @@ -104,9 +102,8 @@ class CoursesController < ApplicationController end def cache_sweep - expire_fragment(:action => 'show', :part => 'right') - expire_fragment(:action => 'show', :part => 'left') - expire_fragment(:action => 'show') - expire_fragment(:action => 'index') + expire_fragment(course_path(@course.id, :part => 'right')) + expire_fragment(course_path(@course.id)) + expire_fragment(courses_path) end end diff --git a/app/controllers/events_controller.rb b/app/controllers/events_controller.rb index 9ecf486..a55cf27 100644 --- a/app/controllers/events_controller.rb +++ b/app/controllers/events_controller.rb @@ -14,7 +14,7 @@ class EventsController < ApplicationController before_filter :find_event, :except => [ :mini_calendar, :undelete ] - after_filter :cache_sweep, :only => [ :create, :update, :destroy ] + #after_filter :cache_sweep, :only => [ :create, :update, :destroy ] def index @events = @course.events @@ -113,7 +113,7 @@ class EventsController < ApplicationController end def cache_sweep - expire_fragment(:controller => 'courses', :action => 'show', :part => 'right') - expire_fragment(:action => 'index') + expire_fragment(course_path(@course.id, :part => 'right')) + expire_fragment(course_events_path(@course.id)) end end diff --git a/app/controllers/news_controller.rb b/app/controllers/news_controller.rb index 623bd6f..bcb00da 100644 --- a/app/controllers/news_controller.rb +++ b/app/controllers/news_controller.rb @@ -18,7 +18,7 @@ class NewsController < ApplicationController # :redirect_to => { :action => :list } before_filter :find_new, :except => [ :undelete ] - after_filter :cache_sweep, :only => [ :create, :update, :destroy ] + #after_filter :cache_sweep, :only => [ :create, :update, :destroy ] def index @news = @course.news @@ -105,7 +105,7 @@ class NewsController < ApplicationController end def cache_sweep - expire_fragment(:controller => 'courses', :action => 'show', :part => 'right') - expire_fragment(:action => 'index') + expire_fragment(course_path(@course.id, :part => :right)) + expire_fragment(course_news_index_path(@course.id)) end end diff --git a/app/controllers/stylesheets_controller.rb b/app/controllers/stylesheets_controller.rb index 6b620f1..131ab6d 100644 --- a/app/controllers/stylesheets_controller.rb +++ b/app/controllers/stylesheets_controller.rb @@ -14,7 +14,7 @@ class StylesheetsController < ApplicationController layout nil - caches_page :wiki + caches_page :wiki, :color before_filter :set_headers private diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 05829e0..217f97a 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -111,7 +111,7 @@ class UsersController < ApplicationController @events = [] if params[:format] == 'html' - return unless require_login + return require_login unless logged_in? @user = @current_user else @user = User.find_by_secret(params[:secret]) @@ -119,7 +119,7 @@ class UsersController < ApplicationController unless @user.courses.empty? @news = News.find(:all, :conditions => [ 'receiver_id in (?)', @user.courses ], - :order => 'timestamp desc', :limit => 5) + :order => 'timestamp desc', :limit => 20) @events = Event.find(:all, :conditions => [ 'course_id in (?) and (time > ?) and (time < ?)', @user.courses, 1.day.ago, 21.days.from_now ], :order => 'time') end diff --git a/app/controllers/wiki_controller.rb b/app/controllers/wiki_controller.rb index 3aeb9c3..7b361db 100644 --- a/app/controllers/wiki_controller.rb +++ b/app/controllers/wiki_controller.rb @@ -16,7 +16,9 @@ class WikiController < ApplicationController verify :params => :text, :only => :preview, :redirect_to => { :action => :show } verify :params => [:from, :to], :only => :diff, :redirect_to => { :action => :versions } - after_filter :cache_sweep, :only => [ :create, :update, :destroy ] + #after_filter :cache_sweep, :only => [ :create, :update, :destroy, :move_up, + # :move_down, :undelete ] + before_filter :find_wiki, :except => [ :preview, :undelete ] before_filter :require_login, :only => [ :new, :create, :edit, :update, :destroy, :move_up, :move_down, :undelete ] @@ -158,7 +160,7 @@ class WikiController < ApplicationController end def cache_sweep - expire_fragment(:controller => 'courses', :action => 'show') - expire_fragment(:action => 'show') + expire_fragment course_path(@course.id) + expire_fragment course_wiki_path(@course.id, @wiki_page.id) end end diff --git a/app/views/courses/_left_panel.html.haml b/app/views/courses/_left_panel.html.haml index c4d1ed1..c21c2e2 100644 --- a/app/views/courses/_left_panel.html.haml +++ b/app/views/courses/_left_panel.html.haml @@ -1,3 +1,2 @@ -- cache(:controller => 'courses', :action => 'show', :id => @course, :part => 'left') do - = render 'widgets/menu_disciplina' - = render 'widgets/menu_user' += render 'widgets/menu_disciplina' += render 'widgets/menu_user' diff --git a/app/views/courses/_right_panel.html.haml b/app/views/courses/_right_panel.html.haml index 599b849..23f86b3 100644 --- a/app/views/courses/_right_panel.html.haml +++ b/app/views/courses/_right_panel.html.haml @@ -1,3 +1,3 @@ -- cache(:controller => 'courses', :action => 'show', :id => @course, :part => 'right') do - = render 'widgets/calendario' - = render 'widgets/news' +-# cache(course_path(@course.id, :part => :right)) do += render 'widgets/calendario' += render 'widgets/news' diff --git a/app/views/courses/index.html.haml b/app/views/courses/index.html.haml index fd02168..f5475d2 100644 --- a/app/views/courses/index.html.haml +++ b/app/views/courses/index.html.haml @@ -1,30 +1,30 @@ .cmd = action_icon('add', 'Cadastrar nova disciplina', new_course_url) if admin? -- cache do - %h4.title= App.title - %h1.title Disciplinas - - .box - %ul - - if logged_in? - %h3 Disciplinas Matriculadas - - if @current_user.courses.empty? - %li.no_itens Nenhuma disciplina matriculada - - for course in @current_user.courses - %li{highlight(course.id)} - .right - = action_icon('subtract', 'Desmatricular-se', unenroll_course_url(course)) - = link_to h(course.full_name), course_url(course) - - - old_period = 0 - - for course in @courses - - if course.period != old_period - %h3= (course.period == 99 ? "Optativas" : "Semestre #{course.period}") - - old_period = course.period +%h4.title= App.title +%h1.title Disciplinas +.box + %ul + - if logged_in? + %h3 Disciplinas Matriculadas + - if @current_user.courses.empty? + %li.no_itens Nenhuma disciplina matriculada + - for course in @current_user.courses %li{highlight(course.id)} .right - = action_icon('add', 'Matricular-se', enroll_course_url(course)) + = action_icon('subtract', 'Desmatricular-se', unenroll_course_url(course)) = link_to h(course.full_name), course_url(course) + -# cache(courses_path) do + - old_period = 0 + - for course in @courses + - if course.period != old_period + %h3= (course.period == 99 ? "Optativas" : "Semestre #{course.period}") + - old_period = course.period + + %li + .right + = action_icon('add', 'Matricular-se', enroll_course_url(course)) + = link_to h(course.full_name), course_url(course) + diff --git a/app/views/courses/show.html.haml b/app/views/courses/show.html.haml index 4c3d814..fd2f6b4 100644 --- a/app/views/courses/show.html.haml +++ b/app/views/courses/show.html.haml @@ -1,31 +1,31 @@ .cmd - if admin? = action_icon 'edit', 'Editar disciplina', edit_course_url - /= action_icon 'trash', 'Excluir disciplina', course_url, :confirm => 'Tem certeza que deseja excluir?', :method => :delete + =# action_icon 'trash', 'Excluir disciplina', course_url, :confirm => 'Tem certeza que deseja excluir?', :method => :delete -- cache do +-# cache(course_path(@course.id)) do - %h4.title Disciplina - %h1.title= h(@course.full_name) +%h4.title Disciplina +%h1.title= h(@course.full_name) - %p= wiki @course.description +%p= wiki @course.description - .box - .cmd - = action_icon 'add', 'Adicionar página wiki', new_course_wiki_url(@course) - - %h3 Páginas Wiki - %ul.wiki - - @course.wiki_pages.each do |wiki| - %li{highlight(wiki.id)} - .cmd{:style => 'margin-bottom: -27px; margin-top: -9px;'} - =action_icon 'arrow2_n', 'Mover para cima', move_up_course_wiki_url(@course, wiki) unless wiki.first? - =action_icon 'arrow2_s', 'Mover para baixo', move_down_course_wiki_url(@course, wiki) unless wiki.last? - - if wiki.last? - %span{:style => 'margin-right: 14px'}   - =link_to h(wiki.title), course_wiki_url(@course, wiki) - - if @course.wiki_pages.empty? - %li.no_itens Nenhuma página wiki +.box + .cmd + = action_icon 'add', 'Adicionar página wiki', new_course_wiki_url(@course) + + %h3 Páginas Wiki + %ul.wiki + - @course.wiki_pages.each do |wiki| + %li + .cmd{:style => 'margin-bottom: -27px; margin-top: -9px;'} + =action_icon 'arrow2_n', 'Mover para cima', move_up_course_wiki_url(@course, wiki) unless wiki.first? + =action_icon 'arrow2_s', 'Mover para baixo', move_down_course_wiki_url(@course, wiki) unless wiki.last? + - if wiki.last? + %span{:style => 'margin-right: 14px'}   + =link_to h(wiki.title), course_wiki_url(@course, wiki) + - if @course.wiki_pages.empty? + %li.no_itens Nenhuma página wiki .box .cmd= action_icon 'add', 'Adicionar anexo', new_course_attachment_url(@course) @@ -38,3 +38,4 @@ = link_to h(att.file_name), course_attachment_url(@course, att) - if @course.attachments.empty? %li.no_itens Nenhum arquivo + diff --git a/app/views/events/index.html.haml b/app/views/events/index.html.haml index 310340b..f93f195 100644 --- a/app/views/events/index.html.haml +++ b/app/views/events/index.html.haml @@ -1,37 +1,37 @@ = javascript_include_tag 'events' -- cache do +-# cache(course_events_path(@course.id)) do - - last_date = nil +- last_date = nil - .cmd - = action_icon 'add', 'Adicionar evento', new_course_event_url +.cmd + = action_icon 'add', 'Adicionar evento', new_course_event_url - %h4.title= h(@course.full_name) - %h1.title Calendário +%h4.title= h(@course.full_name) +%h1.title Calendário - .box.div_calendario - - if !@events.empty? - %table - - @events.each do |event| - %tr[event] - %td.top.aright{:width => '1%'} - = event.time.strftime("%d de %B") #unless event.time == last_date - %td.top{:width => '1%'} - = event.time.strftime("%H:%M") - %td.top - .title=link_to h(event.title), course_event_url(@course, event) - .description{:style => (event.id == params[:id].to_i ? '' : 'display: none')} - %div.cmd - = action_icon 'edit', 'Editar', edit_course_event_url(@course, event) - = action_icon 'trash', 'Excluir', course_event_url(@course, event), :confirm => 'Tem certeza que deseja excluir?', :method => :delete - = h(event.description) - = "Sem descrição" if event.description.empty? +.box.div_calendario + - if !@events.empty? + %table + - @events.each do |event| + %tr[event] + %td.top.aright{:width => '1%'} + = event.time.strftime("%d de %B") #unless event.time == last_date + %td.top{:width => '1%'} + = event.time.strftime("%H:%M") + %td.top + .title=link_to h(event.title), course_event_url(@course, event) + .description{:style => (event.id == params[:id].to_i ? '' : 'display: none')} + %div.cmd + = action_icon 'edit', 'Editar', edit_course_event_url(@course, event) + = action_icon 'trash', 'Excluir', course_event_url(@course, event), :confirm => 'Tem certeza que deseja excluir?', :method => :delete + = h(event.description) + = "Sem descrição" if event.description.empty? - - last_date = event.time - - else - .box - %ul - %li.no_itens Nenhum evento + - last_date = event.time + - else + .box + %ul + %li.no_itens Nenhum evento - %br +%br diff --git a/app/views/layouts/base.html.haml b/app/views/layouts/base.html.haml index 488b918..fe5da45 100644 --- a/app/views/layouts/base.html.haml +++ b/app/views/layouts/base.html.haml @@ -7,8 +7,8 @@ %meta{'name' => 'robots', :content => 'noindex,nofollow'} %meta{'http-equiv' => 'Content-Type', 'content' => 'text/html; charset=UTF-8'} - %link{'href' => "#{App.base_path}/stylesheets/wiki.css", 'rel' => 'Stylesheet', 'type' => %'text/css'} - %link#css_color{'href' => "#{App.base_path}/stylesheets/themes/color.#@color.css", 'rel' => 'Stylesheet', 'type' => %'text/css'} + %link{'href' => "#{App.base_path}/stylesheets/cache/wiki.css", 'rel' => 'Stylesheet', 'type' => %'text/css'} + %link#css_color{'href' => "#{App.base_path}/stylesheets/cache/color.#@color.css", 'rel' => 'Stylesheet', 'type' => %'text/css'} %script{:type => 'text/javascript'} == BASE_PATH = "#{App.base_path}"; diff --git a/app/views/news/index.html.haml b/app/views/news/index.html.haml index cb5213c..e4e46e7 100644 --- a/app/views/news/index.html.haml +++ b/app/views/news/index.html.haml @@ -1,31 +1,31 @@ = javascript_include_tag 'news' -- cache do +-# cache(course_news_index_path(@course.id)) do - .cmd - = action_icon 'add', 'Adicionar', new_course_news_url +.cmd + = action_icon 'add', 'Adicionar', new_course_news_url - %h4.title= h(@course.full_name) - %h1.title Notícias +%h4.title= h(@course.full_name) +%h1.title Notícias - = auto_discovery_link_tag :rss, formatted_course_news_index_url(@course, :rss) += auto_discovery_link_tag :rss, formatted_course_news_index_url(@course, :rss) - .box.div_news - - if !@course.news.empty? - %table - - @course.news.each do |n| - %tr[n] - %td.top.aright{:width => '1%'} - = n.timestamp.strftime("%d de %B") - %td - .title= link_to h(n.title), course_news_url(@course, n) - .description{:style => (n.id == params[:id].to_i ? '' : 'display: none')} - .cmd - = action_icon 'edit', 'Editar', edit_course_news_url(@course, n) - = action_icon 'trash', 'Excluir', course_news_url(@course, n), :confirm => 'Tem certeza que deseja excluir?', :method => :delete - = h(n.body) - = "Sem descrição" if n.body.empty? - - else - .box - %ul - %li.no_itens Nenhuma notícia +.box.div_news + - if !@course.news.empty? + %table + - @course.news.each do |n| + %tr[n] + %td.top.aright{:width => '1%'} + = n.timestamp.strftime("%d de %B") + %td + .title= link_to h(n.title), course_news_url(@course, n) + .description{:style => (n.id == params[:id].to_i ? '' : 'display: none')} + .cmd + = action_icon 'edit', 'Editar', edit_course_news_url(@course, n) + = action_icon 'trash', 'Excluir', course_news_url(@course, n), :confirm => 'Tem certeza que deseja excluir?', :method => :delete + = h(n.body) + = "Sem descrição" if n.body.empty? + - else + .box + %ul + %li.no_itens Nenhuma notícia diff --git a/app/views/users/index.html.haml b/app/views/users/index.html.haml index a1331eb..baafdfa 100644 --- a/app/views/users/index.html.haml +++ b/app/views/users/index.html.haml @@ -1,7 +1,7 @@ -- cache do - %h4.title= App.title - %h1.title Usuários +-# cache(users_path) do +%h4.title= App.title +%h1.title Usuários - .box - %ul - = render :partial => @users +.box + %ul + = render :partial => @users diff --git a/app/views/users/show.html.haml b/app/views/users/show.html.haml index 753b8d4..29663d7 100644 --- a/app/views/users/show.html.haml +++ b/app/views/users/show.html.haml @@ -1,14 +1,14 @@ -- cache do - #users - .cmd - = action_icon('edit', 'Editar perfil', edit_user_url) if admin? or @current_user == @user - /= action_icon 'trash', 'Excluir usuário', user_url, :confirm => 'Tem certeza que deseja excluir?', :method => :delete +#users + .cmd + = action_icon('edit', 'Editar perfil', edit_user_url) if admin? or @current_user == @user + =# action_icon 'trash', 'Excluir usuário', user_url, :confirm => 'Tem certeza que deseja excluir?', :method => :delete - .card - %img.avatar{:src => gravatar_url_for(@user.email)} - %h1.title= h(@user.display_name) - %p= h(@user.name) - %p= "Membro desde {c}"[:member_since, @user.created_at.strftime("%d de %B de %Y")] - %p= "Última visita há {c}"[:last_seen, distance_of_time_in_words(Time.now, @user.last_seen)] + .card + %img.avatar{:src => gravatar_url_for(@user.email)} + %h1.title= h(@user.display_name) + %p= h(@user.name) + %p= "Membro desde {c}"[:member_since, @user.created_at.strftime("%d de %B de %Y")] + %p= "Última visita há {c}"[:last_seen, distance_of_time_in_words(Time.now, @user.last_seen)] - = wiki @user.description if !@user.description.blank? + -# cache(user_path(@user.id)) do + = wiki @user.description if !@user.description.blank? diff --git a/app/views/wiki/show.html.haml b/app/views/wiki/show.html.haml index 15afdd8..1685397 100644 --- a/app/views/wiki/show.html.haml +++ b/app/views/wiki/show.html.haml @@ -1,3 +1,5 @@ +-# cache(course_wiki_path(@course.id, @wiki_page.id)) do + = javascript_include_tag 'wiki' .cmd @@ -5,12 +7,7 @@ = action_icon 'undo', 'Historico', versions_course_wiki_url = action_icon 'trash', 'Excluir página wiki', course_wiki_url, :confirm => 'Tem certeza que deseja excluir?', :method => :delete -- cache(:action => 'show', :short_name => h(@course.short_name), :title => h(@wiki_page.title) ) do - - %h4.title= h(@course.full_name) - %h1.title= h(@wiki_page.title) - #wiki_text - = @wiki_page.to_html - -%script{:language => 'javascript'} - == enumerate_headers(); +%h4.title= h(@course.full_name) +%h1.title= h(@wiki_page.title) +#wiki_text + = @wiki_page.to_html diff --git a/config/environments/production.rb b/config/environments/production.rb index 1e43a19..5a4e2b1 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -9,7 +9,7 @@ config.cache_classes = true # Full error reports are disabled and caching is turned on config.action_controller.consider_all_requests_local = false -config.action_controller.perform_caching = false +config.action_controller.perform_caching = true # Enable serving of images, stylesheets, and javascripts from an asset server # config.action_controller.asset_host = "http://assets.example.com" diff --git a/config/routes.rb b/config/routes.rb index da33f32..e0dff5e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -75,8 +75,8 @@ ActionController::Routing::Routes.draw do |map| map.formatted_dashboard '/dashboard/:secret.:format', :controller => 'users', :action => 'dashboard' # Stylesheets - map.connect 'stylesheets/:action.:format', :controller => 'stylesheets' - map.connect 'stylesheets/themes/:action.:color.:format', :controller => 'stylesheets' + map.connect 'stylesheets/cache/:action.:format', :controller => 'stylesheets' + map.connect 'stylesheets/cache/:action.:color.:format', :controller => 'stylesheets' # Front page map.index '', :controller => 'courses', :action => 'index' diff --git a/db/schema.rb b/db/schema.rb index dd24f78..1670c83 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -73,8 +73,8 @@ ActiveRecord::Schema.define(:version => 32) do t.datetime "updated_at" end - add_index "sessions", ["session_id"], :name => "index_sessions_on_session_id" add_index "sessions", ["updated_at"], :name => "index_sessions_on_updated_at" + add_index "sessions", ["session_id"], :name => "index_sessions_on_session_id" create_table "users", :force => true do |t| t.string "login", :null => false