mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-05-24 08:52:14 -04:00
cache posts/forums on homepage
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
class ForumsController < ApplicationController
|
||||
load_and_authorize_resource
|
||||
|
||||
cache_sweeper :forum_sweeper
|
||||
|
||||
# GET /forums
|
||||
# GET /forums.json
|
||||
def index
|
||||
|
||||
16
app/models/forum_sweeper.rb
Normal file
16
app/models/forum_sweeper.rb
Normal file
@@ -0,0 +1,16 @@
|
||||
class ForumSweeper < ActionController::Caching::Sweeper
|
||||
observe Forum
|
||||
|
||||
def after_create(forum)
|
||||
expire_fragment('homepage_forums')
|
||||
end
|
||||
|
||||
def after_update(forum)
|
||||
expire_fragment('homepage_forums')
|
||||
end
|
||||
|
||||
def after_destroy(forum)
|
||||
expire_fragment('homepage_forums')
|
||||
end
|
||||
|
||||
end
|
||||
@@ -1,16 +1,18 @@
|
||||
%h2 Discussion
|
||||
|
||||
- posts = Post.limit(6)
|
||||
- if posts
|
||||
=render :partial => "posts/summary", :locals => { :posts => posts, :howmany => 6 }
|
||||
- cache "recent_posts" do
|
||||
- posts = Post.limit(6)
|
||||
- if posts
|
||||
=render :partial => "posts/summary", :locals => { :posts => posts, :howmany => 6 }
|
||||
|
||||
- forums = Forum.all
|
||||
- if forums
|
||||
%ul.inline
|
||||
%li
|
||||
%strong Forums:
|
||||
- forums.each do |f|
|
||||
%li= link_to f.name, f
|
||||
- cache "homepage_forums" do
|
||||
- forums = Forum.all
|
||||
- if forums
|
||||
%ul.inline
|
||||
%li
|
||||
%strong Forums:
|
||||
- forums.each do |f|
|
||||
%li= link_to f.name, f
|
||||
|
||||
%p.text-right
|
||||
= link_to "View all posts »", posts_path
|
||||
|
||||
Reference in New Issue
Block a user