improve closet performance by caching item link
This commit is contained in:
parent
4a69772cd2
commit
1e3938eea9
7 changed files with 28 additions and 42 deletions
|
@ -1,5 +1,3 @@
|
|||
# requires item sweeper at bottom
|
||||
|
||||
class Item < ActiveRecord::Base
|
||||
include PrettyParam
|
||||
|
||||
|
@ -836,6 +834,3 @@ class Item < ActiveRecord::Base
|
|||
|
||||
class SearchError < ArgumentError;end
|
||||
end
|
||||
|
||||
require 'item_sweeper'
|
||||
|
||||
|
|
17
app/models/item_observer.rb
Normal file
17
app/models/item_observer.rb
Normal file
|
@ -0,0 +1,17 @@
|
|||
class ItemObserver < ActionController::Caching::Sweeper
|
||||
def after_update(item)
|
||||
Rails.logger.debug "Item #{item.id} was just updated"
|
||||
expire_cache_for(item)
|
||||
end
|
||||
|
||||
def after_destroy(item)
|
||||
Rails.logger.debug "Item #{item.id} was just destroyed"
|
||||
expire_cache_for(item)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def expire_cache_for(item)
|
||||
ActionController::Base.new.expire_fragment("items/#{item.id}#item_link_partial")
|
||||
end
|
||||
end
|
|
@ -1,26 +0,0 @@
|
|||
class ItemSweeper < ActionController::Caching::Sweeper
|
||||
observe Item
|
||||
|
||||
def after_update(item)
|
||||
expire_cache_for(item)
|
||||
end
|
||||
|
||||
def after_destroy(item)
|
||||
expire_cache_for(item)
|
||||
end
|
||||
|
||||
private
|
||||
def expire_cache_for(item)
|
||||
options = {:controller => 'items', :action => 'show', :id => item.id}
|
||||
expire_action(options)
|
||||
end
|
||||
|
||||
def expire_action(options)
|
||||
if @controller
|
||||
super
|
||||
elsif LocalImpressHost
|
||||
@tmp_controller ||= SweeperController.new
|
||||
@tmp_controller.expire_action_proxy(options.dup)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,13 +1,13 @@
|
|||
.closet-list{'data-id' => closet_list.id, 'data-hangers-count' => closet_list.hangers.count, :id => "closet-list-#{closet_list.id}"}
|
||||
.closet-list{'data-id' => closet_list.id, 'data-hangers-count' => closet_list.hangers.size, :id => "closet-list-#{closet_list.id}"}
|
||||
%header
|
||||
- if show_controls
|
||||
= form_for [closet_list.user, closet_list], :html => {:class => 'visibility-form'} do |f|
|
||||
= form_for [current_user, closet_list], :html => {:class => 'visibility-form'} do |f|
|
||||
= f.select :visibility, closet_visibility_choices(:human_name)
|
||||
= f.submit "Save"
|
||||
= closet_visibility_descriptions('items in this list')
|
||||
.closet-list-controls
|
||||
= link_to 'Edit', edit_user_closet_list_path(closet_list.user, closet_list)
|
||||
= form_tag user_closet_list_path(closet_list.user, closet_list), :method => 'delete' do
|
||||
= link_to 'Edit', edit_user_closet_list_path(closet_list.user_id, closet_list)
|
||||
= form_tag user_closet_list_path(closet_list.user_id, closet_list), :method => 'delete' do
|
||||
= submit_tag 'Delete', :confirm => closet_list_delete_confirmation(closet_list)
|
||||
%h4= closet_list.name
|
||||
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
.object
|
||||
= render :partial => 'items/item_link', :locals => {:item => item}
|
||||
|
||||
= closeted_icons_for(item)
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
- cache "items/#{item.id}#item_link_partial" do
|
||||
= link_to item_path(item, :q => @query) do
|
||||
= image_tag item.thumbnail_url, :alt => item.description, :title => item.description
|
||||
%span.name= item.name
|
||||
= nc_icon_for(item)
|
||||
= closeted_icons_for(item)
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ module OpenneoImpressItems
|
|||
# config.plugins = [ :exception_notification, :ssl_requirement, :all ]
|
||||
|
||||
# Activate observers that should always be running
|
||||
config.active_record.observers = :item_sweeper, :user_sweeper
|
||||
config.active_record.observers = :item_observer, :user_sweeper
|
||||
|
||||
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
|
||||
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
|
||||
|
|
Loading…
Reference in a new issue