1
0
Fork 0
forked from OpenNeo/impress

home page caching, reset top contributors only when necessary

This commit is contained in:
Emi Matchu 2010-12-11 09:37:39 -05:00
parent 8d20a68a53
commit ca155314fa
7 changed files with 128 additions and 100 deletions

View file

@ -29,9 +29,13 @@ class OutfitsController < ApplicationController
end end
def new def new
@colors = Color.all_ordered_by_name unless fragment_exist?(:action_suffix => 'start_from_scratch_form_content')
@species = Species.all_ordered_by_name @colors = Color.all_ordered_by_name
@top_contributors = User.top_contributors.limit(3) @species = Species.all_ordered_by_name
end
unless fragment_exist?(:action_suffix => 'top_contributors')
@top_contributors = User.top_contributors.limit(User::PreviewTopContributorsCount)
end
end end
def show def show

View file

@ -1,6 +1,8 @@
class PetsController < ApplicationController class PetsController < ApplicationController
rescue_from Pet::PetNotFound, :with => :pet_not_found rescue_from Pet::PetNotFound, :with => :pet_not_found
cache_sweeper :user_sweeper
DESTINATIONS = { DESTINATIONS = {
'needed_items' => '?', 'needed_items' => '?',
'root' => '#', 'root' => '#',

View file

@ -1,5 +1,3 @@
puts 'Hey! Item sweeper!'
class ItemSweeper < ActionController::Caching::Sweeper class ItemSweeper < ActionController::Caching::Sweeper
observe Item observe Item

View file

@ -1,5 +1,6 @@
class User < ActiveRecord::Base class User < ActiveRecord::Base
DefaultAuthServerId = 1 DefaultAuthServerId = 1
PreviewTopContributorsCount = 3
has_many :contributions has_many :contributions
has_many :outfits has_many :outfits
@ -37,4 +38,8 @@ class User < ActiveRecord::Base
end end
user user
end end
def self.points_required_to_pass_top_contributor(offset)
User.top_contributors.select(:points).limit(1).offset(offset).first.points
end
end end

View file

@ -0,0 +1,12 @@
class UserSweeper < ActionController::Caching::Sweeper
observe User
def before_save(user)
if user.points_changed?
points_to_beat = User.points_required_to_pass_top_contributor(User::PreviewTopContributorsCount - 1)
if user.points >= points_to_beat
expire_fragment(:controller => 'outfits', :action => 'new', :action_suffix => 'top_contributors')
end
end
end
end

View file

@ -1,104 +1,111 @@
- hide_home_link - hide_home_link
#outfit-forms #outfit-forms
#pet-preview - cache :action_suffix => 'outfit_forms_intro' do
= image_tag 'default_preview.png', :alt => '' #pet-preview
%span = image_tag 'default_preview.png', :alt => ''
%h1 Dress to Impress %span
%h2 Neopets wearables made easy! %h1 Dress to Impress
%h2 Neopets wearables made easy!
= form_tag load_pet_path, :id => 'load-pet-to-wardrobe' do = form_tag load_pet_path, :id => 'load-pet-to-wardrobe' do
= origin_tag root_path - cache :action_suffix => 'main_load_pet_form_content' do
= destination_tag 'wardrobe' = origin_tag root_path
%fieldset = destination_tag 'wardrobe'
%legend Enter your pet's name %fieldset
= pet_name_tag :id => 'main-pet-name' %legend Enter your pet's name
%button{:type => "submit"} = pet_name_tag :id => 'main-pet-name'
Plan my outfit! %button{:type => "submit"}
Plan my outfit!
= form_tag wardrobe_path, :method => 'get', :id => 'start-from-scratch' do = form_tag wardrobe_path, :method => 'get', :id => 'start-from-scratch' do
%fieldset - cache :action_suffix => 'start_from_scratch_form_content' do
%legend Or start from scratch %fieldset
= pet_attribute_select 'color', @colors, 8 %legend Or start from scratch
= pet_attribute_select 'species', @species = pet_attribute_select 'color', @colors, 8
%input{:type => "submit", :value => "Go"} = pet_attribute_select 'species', @species
%ul#sections %input{:type => "submit", :value => "Go"}
%li - cache :action_suffix => 'sections_and_description' do
%a{:href => "http://forum.openneo.net"} %ul#sections
= image_tag 'forum.png' %li
%h3 %a{:href => "http://forum.openneo.net"}
%a{:href => "http://forum.openneo.net/"} Forum = image_tag 'forum.png'
%div %h3
%h4 Join our community! %a{:href => "http://forum.openneo.net/"} Forum
%p %div
Show off your designs, ask for advice, or play silly forum games %h4 Join our community!
here. %p
%li Show off your designs, ask for advice, or play silly forum games
%a{:href => items_path} here.
= image_tag 'items.png' %li
%h3
%a{:href => items_path} %a{:href => items_path}
Infinite Closet = image_tag 'items.png'
%div %h3
%h4 Looking for something? %a{:href => items_path}
%p Infinite Closet
Take a look through our wearables database! %div
= form_tag items_path, :method => 'get' do %h4 Looking for something?
= text_field_tag 'q', '', :placeholder => raw('search items&hellip;'), :type => 'search' %p
= submit_tag 'search' Take a look through our wearables database!
%li#blog-preview = form_tag items_path, :method => 'get' do
%a{:href => "http://blog.openneo.net"} = text_field_tag 'q', '', :placeholder => raw('search items&hellip;'), :type => 'search'
= image_tag 'blog.png' = submit_tag 'search'
%h3 %li#blog-preview
%a{:href => "http://blog.openneo.net/"} OpenNeo Blog %a{:href => "http://blog.openneo.net"}
%div = image_tag 'blog.png'
%h4 We'll keep you posted! %h3
%p %a{:href => "http://blog.openneo.net/"} OpenNeo Blog
Dress to Impress is always improving, and you can always stay in %div
the loop through our blog. %h4 We'll keep you posted!
#description %p
%h2 Built by you, just for you! Dress to Impress is always improving, and you can always stay in
%p the loop through our blog.
Dress to Impress lets you plan how you want to dress up your Neopets, #description
before you even go shopping! Whenever you give us a Neopet's name, we %h2 Built by you, just for you!
automatically look up what it's wearing and organize the data into %p
our own wearables database &mdash; a community closet, if you will. Dress to Impress lets you plan how you want to dress up your Neopets,
Then you can plan your outfit, mixing and matching various items, so before you even go shopping! Whenever you give us a Neopet's name, we
you can have the best-dressed Neopet in all of Neopia! automatically look up what it's wearing and organize the data into
%p our own wearables database &mdash; a community closet, if you will.
To make all this possible, though, we need your help &mdash; and if Then you can plan your outfit, mixing and matching various items, so
you log in at the top, we'll keep track of your you can have the best-dressed Neopet in all of Neopia!
= link_to 'contributions', contributions_path %p
and award To make all this possible, though, we need your help &mdash; and if
= link_to 'points', top_contributors_path you log in at the top, we'll keep track of your
so you can show off just how dedicated you really are! = link_to 'contributions', contributions_path
#top-contributors and award
%h3 Top Contributors = link_to 'points', top_contributors_path
%ol so you can show off just how dedicated you really are!
- @top_contributors.each do |user| - cache :action_suffix => 'top_contributors' do
%li #top-contributors
= link_to user.name, user_contributions_path(user) %h3 Top Contributors
&mdash; %ol
= user.points - @top_contributors.each do |user|
%a{:href => top_contributors_path} see more %li
= link_to user.name, user_contributions_path(user)
&mdash;
= user.points
%a{:href => top_contributors_path} see more
= form_tag load_pet_path, :id => 'how-can-i-help' do = form_tag load_pet_path, :id => 'how-can-i-help' do
= destination_tag 'needed_items' - cache :action_suffix => 'how_can_i_help_form_content' do
= origin_tag root_path = destination_tag 'needed_items'
%h2 How can I help? = origin_tag root_path
%p %h2 How can I help?
Enter your pet's name, and we'll tell you what items you can help us %p
model. Thanks so much! Enter your pet's name, and we'll tell you what items you can help us
= pet_name_tag model. Thanks so much!
%button{:type => "submit"} = pet_name_tag
Let's model! %button{:type => "submit"}
Let's model!
= form_tag load_pet_path, :id => 'i-found-something' do = form_tag load_pet_path, :id => 'i-found-something' do
= origin_tag root_path - cache :action_suffix => 'i_found_something_form_content' do
%a{:href => bulk_pets_path} = origin_tag root_path
add many pets %a{:href => bulk_pets_path}
%h2 I found something! add many pets
%p %h2 I found something!
Enter the name of the pet you found, and we'll keep a copy of what %p
it's wearing. Thanks so much! Enter the name of the pet you found, and we'll keep a copy of what
= pet_name_tag it's wearing. Thanks so much!
%button{:type => "submit"} = pet_name_tag
I pwn! %button{:type => "submit"}
I pwn!
- content_for :javascripts do - content_for :javascripts do
= include_javascript_libraries :jquery = include_javascript_libraries :jquery
= include_javascripts :new_outfit_package = include_javascripts :new_outfit_package

View file

@ -20,7 +20,7 @@ module OpenneoImpressItems
# config.plugins = [ :exception_notification, :ssl_requirement, :all ] # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
# Activate observers that should always be running # Activate observers that should always be running
config.active_record.observers = :item_sweeper config.active_record.observers = :item_sweeper, :user_sweeper
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. # 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. # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.