diff --git a/app/helpers/items_helper.rb b/app/helpers/items_helper.rb index e7343564..d160a785 100644 --- a/app/helpers/items_helper.rb +++ b/app/helpers/items_helper.rb @@ -120,6 +120,23 @@ module ItemsHelper " (×#{count})".html_safe if count > 1 end + def render_item_link(item) + # I've discovered that checking the cache *before* attempting to render the + # partial is significantly faster: moving the cache line out here instead + # of having it wrap the partial's content speeds up closet_hangers#index + # rendering time by about a factor of 2. It's uglier, but this call happens + # a lot, so the performance gain is definitely worth it. I'd be interested + # in a more legit partial caching abstraction, but, for now, this will do. + # Because this is a returned-string helper, but uses a buffer-output + # helper, we have to do some indirection. Fake that the render is in a + # template, then capture the resulting buffer output. + capture do + localized_cache("items/#{item.id}#item_link_partial") do + safe_concat render(partial: 'items/item_link', locals: {item: item}) + end + end + end + private def build_on_pet_types(species, special_color=nil, &block) diff --git a/app/views/closet_hangers/_closet_hanger.html.haml b/app/views/closet_hangers/_closet_hanger.html.haml index 3db56960..ced215d2 100644 --- a/app/views/closet_hangers/_closet_hanger.html.haml +++ b/app/views/closet_hangers/_closet_hanger.html.haml @@ -1,4 +1,4 @@ %div{'class' => closet_hanger_partial_class(closet_hanger), 'data-item-id' => closet_hanger.item_id, 'data-quantity' => closet_hanger.quantity, 'data-id' => closet_hanger.id} - = render :partial => 'items/item_link', :locals => {:item => closet_hanger.item} + = render_item_link(closet_hanger.item) .quantity{:class => "quantity-#{closet_hanger.quantity}"} %span= closet_hanger.quantity diff --git a/app/views/items/_item.html.haml b/app/views/items/_item.html.haml index 5a3d63ad..5537a308 100644 --- a/app/views/items/_item.html.haml +++ b/app/views/items/_item.html.haml @@ -1,3 +1,3 @@ .object - = render :partial => 'items/item_link', :locals => {:item => item} + = render_item_link(item) = closeted_icons_for(item) diff --git a/app/views/items/_item_link.html.haml b/app/views/items/_item_link.html.haml index 111dee69..e50aafd3 100644 --- a/app/views/items/_item_link.html.haml +++ b/app/views/items/_item_link.html.haml @@ -1,5 +1,4 @@ -- localized_cache "items/#{item.id}#item_link_partial" do - = link_to item_path(item) do - = image_tag item.thumbnail_url, :alt => item.description, :title => item.description - %span.name= item.name - = nc_icon_for(item) += link_to item_path(item) do + = image_tag item.thumbnail_url, :alt => item.description, :title => item.description + %span.name= item.name + = nc_icon_for(item)