Skip to content

Commit

Permalink
以下の修正を行いました.
Browse files Browse the repository at this point in the history
* 復習が多くなると一覧の表示に時間がかかる
* パフォーマンステストを作成して,タグクラウドの生成処理を修正しました.
** closes #40
  • Loading branch information
authorNari committed Jun 7, 2009
1 parent 4e18d9d commit 800b6a7
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 31 deletions.
10 changes: 2 additions & 8 deletions app/controllers/reminders_controller.rb
Expand Up @@ -89,8 +89,8 @@ def completed

def list
@reminders ||= Reminder.lists(:user_id => reminder_user.id, :tag => params["tag"])
logger.debug "DEBUG(list) : @reminders = <#{@reminders.to_yaml}>"
@tags = tag_counts(@reminders)
logger.debug{ "DEBUG(list) : @reminders = <#{@reminders.to_yaml}>" }
@tags = Reminder.tag_counts(:conditions => ["reminders.id IN (?)", @reminders.map(&:id)])
@reminders = @reminders.paginate(:page => params[:page])

respond_to do |format|
Expand Down Expand Up @@ -157,12 +157,6 @@ def save_current_list
}
end

def tag_counts(reminders)
tags = {}
reminders.each{|r| r.tag_counts.each{|t| tags[t.name] ||= []; tags[t.name] << t }}
return tags.values
end

def same_login_user_required
unless current_user?
flash[:notice] = t("permission_denied", :scope => :notice)
Expand Down
9 changes: 1 addition & 8 deletions app/controllers/timelines_controller.rb
Expand Up @@ -22,8 +22,7 @@ def today

def list
@reminders ||= Reminder.lists(:tag => params["tag"])
logger.debug "DEBUG(list) : @reminders = <#{@reminders.to_yaml}>"
@tags = tag_counts(@reminders)
@tags = Reminder.tag_counts(:conditions => ["reminders.id IN (?)", @reminders.map(&:id)])
@reminders = @reminders.paginate(:page => params[:page])

respond_to do |format|
Expand All @@ -41,10 +40,4 @@ def save_current_list
:tag => params[:tag],
}
end

def tag_counts(reminders)
tags = {}
reminders.each{|r| r.tag_counts.each{|t| tags[t.name] ||= []; tags[t.name] << t }}
return tags.values
end
end
12 changes: 1 addition & 11 deletions app/helpers/application_helper.rb
Expand Up @@ -3,6 +3,7 @@
module ApplicationHelper
::WillPaginate::ViewHelpers.pagination_options[:prev_label] = I18n.t(:prev_label, :scope => :paginate)
::WillPaginate::ViewHelpers.pagination_options[:next_label] = I18n.t(:next_label, :scope => :paginate)
include TagsHelper

def action_path(action, options={})
return {:user => (params["user"] || current_user.login), :controller => :reminders, :action => action, :tag => nil}.merge(options)
Expand Down Expand Up @@ -92,17 +93,6 @@ def title_tag_prefix(tag=nil)
return h("/ #{tag}(#{@reminders.size})") if tag
end

def tag_cloud(tags, classes)
return if tags.empty?

max_count = tags.sort_by(&:size).last.size.to_f

tags.each do |tag|
index = ((tag.size / max_count) * (classes.size - 1)).round
yield tag.first, classes[index]
end
end

def hidden_reminder_detail
unless @show_reminder_detail
return "style='display:none;'"
Expand Down
5 changes: 5 additions & 0 deletions config/environments/test.rb
Expand Up @@ -20,3 +20,8 @@
# The :test delivery method accumulates sent emails in the
# ActionMailer::Base.deliveries array.
config.action_mailer.delivery_method = :test

config.action_controller.session = {
:session_key => '_brushup_session',
:secret => "58fc61a60e884d69905c41303193ce06"
}
4 changes: 2 additions & 2 deletions test/fixtures/reminders.yml
Expand Up @@ -65,12 +65,12 @@ list_reminder_with_tag:
<<: *DEFAULT
next_learn_date: <%= Date.tomorrow %>

list_reminder:
list_reminder_2:
<<: *DEFAULT
title: hogehoge
next_learn_date: <%= Date.tomorrow %>

list_reminder:
list_reminder_3:
<<: *DEFAULT
next_learn_date: <%= Date.today %>

Expand Down
4 changes: 2 additions & 2 deletions test/fixtures/taggings.yml
Expand Up @@ -8,12 +8,12 @@ reminder_tags_orange:
taggable: learned_remined_1
taggable_type: Reminder

reminder_tags_orange:
reminder_tags_orange_1:
tag: orange
taggable: deep_clone
taggable_type: Reminder

reminder_tags_orange:
reminder_tags_apple_1:
tag: apple
taggable: deep_clone
taggable_type: Reminder
34 changes: 34 additions & 0 deletions test/performance/timelines_test.rb
@@ -0,0 +1,34 @@
require 'test_helper'
require 'performance_test_help'

# タイムライン画面の負荷チェックを行います
#
# ユーザと復習数が増えるにつれて復習のページ表示が耐えられないほど遅く
# なってきました.
class TimelinesTest < ActionController::PerformanceTest
def setup
create_performance_test_data
Rails.logger.level = ActiveSupport::BufferedLogger::DEBUG
end

def test_list
puts "Reminder count #{Reminder.lists.size}"
puts "Tag count #{Tag.count}"
get '/timelines/list'
end

# def test_user_list
# puts "Reminder count #{Reminder.lists.size}"
# puts "Tag count #{Tag.count}"
# get '/authorNari/list'
# end

private
def create_performance_test_data
1000.times do |i|
reminder = Reminder.new(reminders(:list_reminder).attributes)
reminder.tag_list = "#{rand(i).to_s} #{rand(i).to_s}"
reminder.save!
end
end
end

0 comments on commit 800b6a7

Please sign in to comment.