diff --git a/app/controllers/items_controller.rb b/app/controllers/items_controller.rb index 8d52cb80..eb56a5c1 100644 --- a/app/controllers/items_controller.rb +++ b/app/controllers/items_controller.rb @@ -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 diff --git a/app/controllers/outfits_controller.rb b/app/controllers/outfits_controller.rb index aac9c68f..4325c99b 100644 --- a/app/controllers/outfits_controller.rb +++ b/app/controllers/outfits_controller.rb @@ -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 diff --git a/app/models/item_observer.rb b/app/models/item_observer.rb index 3af52734..62bc5e39 100644 --- a/app/models/item_observer.rb +++ b/app/models/item_observer.rb @@ -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 diff --git a/app/views/items/index.html.haml b/app/views/items/index.html.haml index 34647d1a..4d911ee7 100644 --- a/app/views/items/index.html.haml +++ b/app/views/items/index.html.haml @@ -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 diff --git a/app/views/outfits/new.html.haml b/app/views/outfits/new.html.haml index be6a99e1..84f290cf 100644 --- a/app/views/outfits/new.html.haml +++ b/app/views/outfits/new.html.haml @@ -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