1
0
Fork 0
forked from OpenNeo/impress

add basic caching - TODO: avoid these computations in the controller

This commit is contained in:
Emi Matchu 2013-12-26 23:36:48 -05:00
parent 9a4e114964
commit 7dd2646dbb
3 changed files with 19 additions and 17 deletions

View file

@ -47,7 +47,7 @@ class OutfitsController < ApplicationController
end end
unless localized_fragment_exist?('outfits#new newest_items') unless localized_fragment_exist?('outfits#new newest_items')
newest_items = Item.newest.select([:id, :thumbnail_url, :rarity_index]). newest_items = Item.newest.select([:id, :updated_at, :thumbnail_url, :rarity_index]).
includes(:translations).limit(18) includes(:translations).limit(18)
@newest_modeled_items, @newest_unmodeled_items = @newest_modeled_items, @newest_unmodeled_items =
newest_items.partition(&:predicted_fully_modeled?) newest_items.partition(&:predicted_fully_modeled?)

View file

@ -55,12 +55,14 @@ module OutfitsHelper
end end
def render_predicted_missing_species_by_color(species_by_color) def render_predicted_missing_species_by_color(species_by_color)
# Transform the Color => Array<Species> map into an Array<Pair<Color's
# human name (empty if standard), Array<Species>>>.
# TODO: i18n # TODO: i18n
standard = species_by_color.delete(:standard) standard = species_by_color.delete(:standard)
sorted_pairs = species_by_color.to_a.map { |k, v| [k.human_name, v] }. sorted_pairs = species_by_color.to_a.map { |k, v| [k.human_name, v] }.
sort_by { |k, v| k } sort_by { |k, v| k }
sorted_pairs.unshift(['', standard]) if standard sorted_pairs.unshift(['', standard]) if standard
species_by_color[:standard] = standard # undo mutation species_by_color[:standard] = standard # undo parameter mutation
first = true first = true
contents = sorted_pairs.map { |color_human_name, species| contents = sorted_pairs.map { |color_human_name, species|

View file

@ -74,28 +74,28 @@
#whats-new #whats-new
-# TODO: remove newest_items.header i18n key? -# TODO: remove newest_items.header i18n key?
- localized_cache 'outfits#new newest_items' do -# TODO: i18n all the things
- if @newest_unmodeled_items.present? -# TODO: cache this entire block? or just request newest items every time?
%h3 We need your help! Can you model these items? - if @newest_unmodeled_items.present?
%ul#newest-unmodeled-items %h3 We need your help! Can you model these items?
- @newest_unmodeled_items.each do |item| %ul#newest-unmodeled-items
- @newest_unmodeled_items.each do |item|
- localized_cache "items/#{item.id} modeling_progress updated_at=#{item.updated_at.to_i}" do
%li %li
= link_to image_tag(item.thumbnail_url), item, :class => 'image-link' = link_to image_tag(item.thumbnail_url), item, :class => 'image-link'
= link_to item, :class => 'header' do = link_to item, :class => 'header' do
-# TODO: i18n
%h2= item.name %h2= item.name
-#: we need #{lolremove} more models
%span.meter{style: "width: #{@newest_unmodeled_items_predicted_modeled_ratio[item]*100}%"} %span.meter{style: "width: #{@newest_unmodeled_items_predicted_modeled_ratio[item]*100}%"}
.missing-bodies .missing-bodies
= render_predicted_missing_species_by_color(@newest_unmodeled_items_predicted_missing_species_by_color[item]) = render_predicted_missing_species_by_color(@newest_unmodeled_items_predicted_missing_species_by_color[item])
- if @newest_modeled_items.present? - if @newest_modeled_items.present?
%h3 These items have already been modeled—thanks for your help! %h3 These items have already been modeled—thanks for your help!
%ul#newest-modeled-items %ul#newest-modeled-items
- @newest_modeled_items.each do |item| - @newest_modeled_items.each do |item|
%li.object %li.object
= link_to item, title: item.name, alt: item.name do = link_to item, title: item.name, alt: item.name do
= image_tag item.thumbnail_url = image_tag item.thumbnail_url
= nc_icon_for(item) = nc_icon_for(item)
- localized_cache :action_suffix => 'templates' do - localized_cache :action_suffix => 'templates' do