mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-10-22 06:54:23 -04:00
cache posts/forums on homepage
This commit is contained in:
1 parent
b913ca7a19
commit
347be0633b
3 files changed
+31
-10
No files matched your search
@@ -1,5 +1,8 @@
|
||||
class ForumsController < ApplicationController
|
||||
load_and_authorize_resource
|
||||
|
||||
cache_sweeper :forum_sweeper
|
||||
|
||||
# GET /forums
|
||||
# GET /forums.json
|
||||
def index
|
||||
|
||||
@@ -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