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