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 {
|
||||||
|
unless fragment_exist?('items#index newest_items')
|
||||||
@newest_items = Item.newest.limit(18)
|
@newest_items = Item.newest.limit(18)
|
||||||
current_user.assign_closeted_to_items!(@newest_items) if user_signed_in?
|
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
|
||||||
|
|
||||||
|
unless fragment_exist?('outfits#new newest_items')
|
||||||
@newest_items = Item.newest.select([:id, :name, :thumbnail_url]).limit(9)
|
@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,6 +14,7 @@
|
||||||
= will_paginate @items
|
= will_paginate @items
|
||||||
- else
|
- else
|
||||||
#search-info
|
#search-info
|
||||||
|
- cache :action_suffix => 'search_help' do
|
||||||
#search-help
|
#search-help
|
||||||
%h2 Find what you're looking for
|
%h2 Find what you're looking for
|
||||||
%dl
|
%dl
|
||||||
|
@ -35,10 +36,12 @@
|
||||||
%dt type:hat
|
%dt type:hat
|
||||||
%dd returns any item that fills a "hat" zone
|
%dd returns any item that fills a "hat" zone
|
||||||
|
|
||||||
|
- cache 'items#index newest_items' do
|
||||||
#search-new-items
|
#search-new-items
|
||||||
%h2 Newest items
|
%h2 Newest items
|
||||||
= render @newest_items
|
= render @newest_items
|
||||||
|
|
||||||
|
- cache :action_suffix => 'species_search_links' do
|
||||||
#species-search-links
|
#species-search-links
|
||||||
%h2 Can't decide? Search by species
|
%h2 Can't decide? Search by species
|
||||||
= standard_species_search_links
|
= standard_species_search_links
|
||||||
|
|
|
@ -94,6 +94,7 @@
|
||||||
%div
|
%div
|
||||||
%a#blog-preview-linkback{:href => 'http://blog.openneo.net/'} OpenNeo Blog
|
%a#blog-preview-linkback{:href => 'http://blog.openneo.net/'} OpenNeo Blog
|
||||||
|
|
||||||
|
- cache 'outfits#new newest_items' do
|
||||||
#newest-items
|
#newest-items
|
||||||
%h2 New Items
|
%h2 New Items
|
||||||
%ul
|
%ul
|
||||||
|
|
Loading…
Reference in a new issue