cache newest items on homepage and items#index
This commit is contained in:
parent
1e3938eea9
commit
f6d34841ec
5 changed files with 57 additions and 35 deletions
|
@ -34,8 +34,9 @@ class ItemsController < ApplicationController
|
|||
else
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
@newest_items = Item.newest.limit(18)
|
||||
current_user.assign_closeted_to_items!(@newest_items) if user_signed_in?
|
||||
unless fragment_exist?('items#index newest_items')
|
||||
@newest_items = Item.newest.limit(18)
|
||||
end
|
||||
}
|
||||
format.js { render :json => {:error => '$q required'}}
|
||||
end
|
||||
|
|
|
@ -57,7 +57,10 @@ class OutfitsController < ApplicationController
|
|||
@top_contributors = User.top_contributors.limit(User::PreviewTopContributorsCount)
|
||||
end
|
||||
|
||||
@newest_items = Item.newest.select([:id, :name, :thumbnail_url]).limit(9)
|
||||
unless fragment_exist?('outfits#new newest_items')
|
||||
@newest_items = Item.newest.select([:id, :name, :thumbnail_url]).limit(9)
|
||||
end
|
||||
|
||||
@latest_contribution = Contribution.recent.first
|
||||
Contribution.preload_contributeds_and_parents([@latest_contribution])
|
||||
end
|
||||
|
|
|
@ -1,4 +1,9 @@
|
|||
class ItemObserver < ActionController::Caching::Sweeper
|
||||
def after_create(item)
|
||||
Rails.logger.debug "Item #{item.id} was just created"
|
||||
expire_newest_items
|
||||
end
|
||||
|
||||
def after_update(item)
|
||||
Rails.logger.debug "Item #{item.id} was just updated"
|
||||
expire_cache_for(item)
|
||||
|
@ -11,7 +16,16 @@ class ItemObserver < ActionController::Caching::Sweeper
|
|||
|
||||
private
|
||||
|
||||
def controller
|
||||
@controller ||= ActionController::Base.new
|
||||
end
|
||||
|
||||
def expire_cache_for(item)
|
||||
ActionController::Base.new.expire_fragment("items/#{item.id}#item_link_partial")
|
||||
controller.expire_fragment("items/#{item.id}#item_link_partial")
|
||||
end
|
||||
|
||||
def expire_newest_items
|
||||
controller.expire_fragment('outfits#new newest_items')
|
||||
controller.expire_fragment('items#index newest_items')
|
||||
end
|
||||
end
|
||||
|
|
|
@ -14,32 +14,35 @@
|
|||
= will_paginate @items
|
||||
- else
|
||||
#search-info
|
||||
#search-help
|
||||
%h2 Find what you're looking for
|
||||
%dl
|
||||
%dt kreludor "altador cup" -background
|
||||
%dd
|
||||
returns any item with the word "kreludor" and the phrase "altador cup"
|
||||
in it, but not the word "background"
|
||||
%dt hat user:owns
|
||||
%dd
|
||||
returns
|
||||
= link_to 'items that you own', your_items_path
|
||||
with the word "hat"
|
||||
%dt blue is:nc
|
||||
%dd returns any NC Mall item with the word "blue" in it
|
||||
%dt collar -is:pb
|
||||
%dd returns any item with the word "collar" in it that isn't from a paint brush
|
||||
%dt species:shoyru
|
||||
%dd returns any item a Shoyru can wear
|
||||
%dt type:hat
|
||||
%dd returns any item that fills a "hat" zone
|
||||
- cache :action_suffix => 'search_help' do
|
||||
#search-help
|
||||
%h2 Find what you're looking for
|
||||
%dl
|
||||
%dt kreludor "altador cup" -background
|
||||
%dd
|
||||
returns any item with the word "kreludor" and the phrase "altador cup"
|
||||
in it, but not the word "background"
|
||||
%dt hat user:owns
|
||||
%dd
|
||||
returns
|
||||
= link_to 'items that you own', your_items_path
|
||||
with the word "hat"
|
||||
%dt blue is:nc
|
||||
%dd returns any NC Mall item with the word "blue" in it
|
||||
%dt collar -is:pb
|
||||
%dd returns any item with the word "collar" in it that isn't from a paint brush
|
||||
%dt species:shoyru
|
||||
%dd returns any item a Shoyru can wear
|
||||
%dt type:hat
|
||||
%dd returns any item that fills a "hat" zone
|
||||
|
||||
#search-new-items
|
||||
%h2 Newest items
|
||||
= render @newest_items
|
||||
- cache 'items#index newest_items' do
|
||||
#search-new-items
|
||||
%h2 Newest items
|
||||
= render @newest_items
|
||||
|
||||
#species-search-links
|
||||
%h2 Can't decide? Search by species
|
||||
= standard_species_search_links
|
||||
- cache :action_suffix => 'species_search_links' do
|
||||
#species-search-links
|
||||
%h2 Can't decide? Search by species
|
||||
= standard_species_search_links
|
||||
|
||||
|
|
|
@ -94,11 +94,12 @@
|
|||
%div
|
||||
%a#blog-preview-linkback{:href => 'http://blog.openneo.net/'} OpenNeo Blog
|
||||
|
||||
#newest-items
|
||||
%h2 New Items
|
||||
%ul
|
||||
- @newest_items.each do |item|
|
||||
= link_to image_tag(item.thumbnail_url), item
|
||||
- cache 'outfits#new newest_items' do
|
||||
#newest-items
|
||||
%h2 New Items
|
||||
%ul
|
||||
- @newest_items.each do |item|
|
||||
= link_to image_tag(item.thumbnail_url), item
|
||||
|
||||
- content_for :javascripts do
|
||||
= include_javascript_libraries :jquery
|
||||
|
|
Loading…
Reference in a new issue