use size in stead of count to prevent unnecessary querying

This commit is contained in:
Reinier Balt 2013-04-22 11:11:53 +02:00
parent caec4f214a
commit a987ff3727
5 changed files with 13 additions and 8 deletions

View file

@ -78,8 +78,8 @@ class StatsController < ApplicationController
def actions_done_last30days_data def actions_done_last30days_data
# get actions created and completed in the past 30 days. # get actions created and completed in the past 30 days.
@actions_done_last30days = current_user.todos.completed_after(@cut_off_month).select("completed_at") @actions_done_last30days = current_user.todos.completed_after(@cut_off_30days).select("completed_at")
@actions_created_last30days = current_user.todos.created_after(@cut_off_month).select("created_at") @actions_created_last30days = current_user.todos.created_after(@cut_off_30days).select("created_at")
# convert to array. 30+1 to have 30 complete days and one current day [0] # convert to array. 30+1 to have 30 complete days and one current day [0]
@actions_done_last30days_array = convert_to_days_from_today_array(@actions_done_last30days, 31, :completed_at) @actions_done_last30days_array = convert_to_days_from_today_array(@actions_done_last30days, 31, :completed_at)
@ -351,6 +351,7 @@ class StatsController < ApplicationController
@cut_off_year = 12.months.ago.beginning_of_day @cut_off_year = 12.months.ago.beginning_of_day
@cut_off_year_plus3 = 15.months.ago.beginning_of_day @cut_off_year_plus3 = 15.months.ago.beginning_of_day
@cut_off_month = 1.month.ago.beginning_of_day @cut_off_month = 1.month.ago.beginning_of_day
@cut_off_30days = 30.days.ago.beginning_of_day
end end
def get_ids_from (actions, week_from, week_to, at_end) def get_ids_from (actions, week_from, week_to, at_end)

View file

@ -1,7 +1,7 @@
<%- <%-
url_array = Array.new(13){ |i| url_for :controller => 'stats', :action => 'actions_done_last_years'} url_array = Array.new(13){ |i| url_for :controller => 'stats', :action => 'actions_done_last_years'}
created_count_array = Array.new(13){ |i| @actions_created_last12months.count/12.0 } created_count_array = Array.new(13){ |i| @actions_created_last12months.size/12.0 }
done_count_array = Array.new(13){ |i| @actions_done_last12months.count/12.0 } done_count_array = Array.new(13){ |i| @actions_done_last12months.size/12.0 }
month_names = Array.new(13){ |i| t('date.month_names')[ (Time.now.mon - i -1 ) % 12 + 1 ]} month_names = Array.new(13){ |i| t('date.month_names')[ (Time.now.mon - i -1 ) % 12 + 1 ]}
-%> -%>
&title=<%= t('stats.actions_lastyear_title') %>,{font-size:16},& &title=<%= t('stats.actions_lastyear_title') %>,{font-size:16},&

View file

@ -1,6 +1,6 @@
<%- <%-
created_count_array = Array.new(30){ |i| @actions_created_last30days.count/30.0 } created_count_array = Array.new(30){ |i| @actions_created_last30days.size/30.0 }
done_count_array = Array.new(30){ |i| @actions_done_last30days.count/30.0 } done_count_array = Array.new(30){ |i| @actions_done_last30days.size/30.0 }
# TODO: make the strftime i18n proof # TODO: make the strftime i18n proof
time_labels = Array.new(30){ |i| l(Time.zone.now-i.days, :format => :stats) } time_labels = Array.new(30){ |i| l(Time.zone.now-i.days, :format => :stats) }
-%> -%>

View file

@ -1,6 +1,6 @@
<%- <%-
created_count_array = Array.new(@month_count+1){ |i| @actions_created_last_months.count/@month_count } created_count_array = Array.new(@month_count+1){ |i| @actions_created_last_months.size/@month_count }
done_count_array = Array.new(@month_count+1){ |i| @actions_done_last_months.count/@month_count } done_count_array = Array.new(@month_count+1){ |i| @actions_done_last_months.size/@month_count }
month_names = Array.new(@month_count+1){ |i| t('date.month_names')[ (Time.now.mon - i -1 ) % 12 + 1 ]+ " " + (Time.now - i.months).year.to_s} month_names = Array.new(@month_count+1){ |i| t('date.month_names')[ (Time.now.mon - i -1 ) % 12 + 1 ]+ " " + (Time.now - i.months).year.to_s}
-%> -%>
&title=<%= t('stats.actions_last_year') %>,{font-size:16},& &title=<%= t('stats.actions_last_year') %>,{font-size:16},&

View file

@ -37,6 +37,10 @@ Then /^I should (see|not see) "([^"]*)" in the context container for "([^"]*)"$/
check_xpath_visibility(visible, todo_in_context_container_xpath(find_todo(todo_description), find_context(context_name))) check_xpath_visibility(visible, todo_in_context_container_xpath(find_todo(todo_description), find_context(context_name)))
end end
Then(/^I should (see|not see) "([^"]*)" in the context container of "([^"]*)"$/) do |visible, todo_description, context_name|
step "I should #{visible} \"#{todo_description}\" in the context container for \"#{context_name}\""
end
Then /^I should (see|not see) "([^"]*)" in the container for context "([^"]*)"$/ do |visible, todo_description, context_name| Then /^I should (see|not see) "([^"]*)" in the container for context "([^"]*)"$/ do |visible, todo_description, context_name|
step "I should #{visible} \"#{todo_description}\" in the context container for \"#{context_name}\"" step "I should #{visible} \"#{todo_description}\" in the context container for \"#{context_name}\""
end end