diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index de224c26..f98ac793 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -272,7 +272,8 @@ class ApplicationController < ActionController::Base @source_view = object_name @page_title = t("#{object_name.pluralize}.all_completed_tasks_title", "#{object_name}_name".to_sym => object.name) - @done = object.todos.completed.paginate :page => params[:page], :per_page => 20, :order => 'completed_at DESC', :include => Todo::DEFAULT_INCLUDES + @done = object.todos.completed.reorder('completed_at DESC').includes(Todo::DEFAULT_INCLUDES). + paginate(:page => params[:page], :per_page => 20) @count = @done.size render :template => 'todos/all_done' end diff --git a/app/controllers/todos_controller.rb b/app/controllers/todos_controller.rb index efc484e3..c3796077 100644 --- a/app/controllers/todos_controller.rb +++ b/app/controllers/todos_controller.rb @@ -1270,21 +1270,21 @@ end # all completed todos [today@00:00, today@now] def get_done_today(completed_todos, includes = {:include => Todo::DEFAULT_INCLUDES}) start_of_this_day = Time.zone.now.beginning_of_day - completed_todos.completed_after(start_of_this_day).all(includes) + completed_todos.completed_after(start_of_this_day).includes(includes[:include]) end # all completed todos [begin_of_week, start_of_today] def get_done_rest_of_week(completed_todos, includes = {:include => Todo::DEFAULT_INCLUDES}) start_of_this_week = Time.zone.now.beginning_of_week start_of_this_day = Time.zone.now.beginning_of_day - completed_todos.completed_before(start_of_this_day).completed_after(start_of_this_week).all(includes) + completed_todos.completed_before(start_of_this_day).completed_after(start_of_this_week).includes(includes[:include]) end # all completed todos [begin_of_month, begin_of_week] def get_done_rest_of_month(completed_todos, includes = {:include => Todo::DEFAULT_INCLUDES}) start_of_this_month = Time.zone.now.beginning_of_month start_of_this_week = Time.zone.now.beginning_of_week - completed_todos.completed_before(start_of_this_week).completed_after(start_of_this_month).all(includes) + completed_todos.completed_before(start_of_this_week).completed_after(start_of_this_month).includes(includes[:include]) end def get_not_done_todos diff --git a/db/migrate/002_add_user_id.rb b/db/migrate/002_add_user_id.rb index 0f7e0f10..335c9813 100644 --- a/db/migrate/002_add_user_id.rb +++ b/db/migrate/002_add_user_id.rb @@ -8,9 +8,9 @@ class AddUserId < ActiveRecord::Migration add_column :contexts, :user_id, :integer, :default => 1 add_column :projects, :user_id, :integer, :default => 1 add_column :todos, :user_id, :integer, :default => 1 - Context.find(:all).each { |context| context.user_id = 1 } - Project.find(:all).each { |project| project.user_id = 1 } - Todo.find(:all).each { |todo| todo.user_id = 1 } + Context.all.each { |context| context.user_id = 1 } + Project.all.each { |project| project.user_id = 1 } + Todo.all.each { |todo| todo.user_id = 1 } end def self.down diff --git a/db/migrate/006_add_preferences_to_user_table.rb b/db/migrate/006_add_preferences_to_user_table.rb index 76669149..68e18a41 100644 --- a/db/migrate/006_add_preferences_to_user_table.rb +++ b/db/migrate/006_add_preferences_to_user_table.rb @@ -4,7 +4,7 @@ class AddPreferencesToUserTable < ActiveRecord::Migration def self.up add_column :users, :preferences, :text - @users = User.find(:all) + @users = User.all @users.each do |u| u.preferences = { "date_format" => "%d/%m/%Y", "week_starts" => "1", "no_completed" => "5", "staleness_starts" => "7", "due_style" => "1", "admin_email" => "butshesagirl@rousette.org.uk"} u.save diff --git a/db/migrate/008_add_subclass_attr_to_todos.rb b/db/migrate/008_add_subclass_attr_to_todos.rb index b89469ad..ff29f25f 100644 --- a/db/migrate/008_add_subclass_attr_to_todos.rb +++ b/db/migrate/008_add_subclass_attr_to_todos.rb @@ -6,7 +6,7 @@ class AddSubclassAttrToTodos < ActiveRecord::Migration def self.up add_column :todos, :type, :string, :null => false, :default => "Immediate" add_column :todos, :show_from, :date - Todo.find(:all).each { |todo| todo.type = "Immediate" } + Todo.all.each { |todo| todo.type = "Immediate" } end def self.down diff --git a/db/migrate/009_add_user_pref_refresh.rb b/db/migrate/009_add_user_pref_refresh.rb index b87e72f8..293b1421 100644 --- a/db/migrate/009_add_user_pref_refresh.rb +++ b/db/migrate/009_add_user_pref_refresh.rb @@ -3,7 +3,7 @@ class AddUserPrefRefresh < ActiveRecord::Migration class User < ActiveRecord::Base; serialize :preferences; end def self.up - @users = User.find(:all) + @users = User.all @users.each do |user| user.preferences.merge!({"refresh" => "0"}) user.save diff --git a/db/migrate/011_pref_to_show_hide_sidebar_items.rb b/db/migrate/011_pref_to_show_hide_sidebar_items.rb index 97bd7f2b..4dc103e0 100644 --- a/db/migrate/011_pref_to_show_hide_sidebar_items.rb +++ b/db/migrate/011_pref_to_show_hide_sidebar_items.rb @@ -3,7 +3,7 @@ class PrefToShowHideSidebarItems < ActiveRecord::Migration class User < ActiveRecord::Base; serialize :preferences; end def self.up - @users = User.find(:all) + @users = User.all @users.each do |user| user.preferences.merge!({"show_completed_projects_in_sidebar" => true}) user.preferences.merge!({"show_hidden_contexts_in_sidebar" => true}) @@ -12,7 +12,7 @@ class PrefToShowHideSidebarItems < ActiveRecord::Migration end def self.down - @users = User.find(:all) + @users = User.all @users.each do |user| user.preferences.delete("show_completed_projects_in_sidebar") user.preferences.delete("show_hidden_contexts_in_sidebar") diff --git a/db/migrate/013_convert_preferences.rb b/db/migrate/013_convert_preferences.rb index df76aeb6..a963be85 100644 --- a/db/migrate/013_convert_preferences.rb +++ b/db/migrate/013_convert_preferences.rb @@ -3,7 +3,7 @@ class ConvertPreferences < ActiveRecord::Migration class User < ActiveRecord::Base; has_one :preference; serialize :preferences; end def self.up - @users = User.find(:all) + @users = User.all @users.each do |user| user.create_preference user.preference.date_format = user.preferences['date_format'] @@ -27,7 +27,7 @@ class ConvertPreferences < ActiveRecord::Migration def self.down add_column :users, :preferences, :text - @users = User.find(:all) + @users = User.all @users.each do |user| user.preferences = { "date_format" => "#{user.preference.date_format}", "week_starts" => "#{user.preference.week_starts}", diff --git a/db/migrate/014_convert_project_to_state_machine.rb b/db/migrate/014_convert_project_to_state_machine.rb index 48b5c21d..8e5c4f4f 100644 --- a/db/migrate/014_convert_project_to_state_machine.rb +++ b/db/migrate/014_convert_project_to_state_machine.rb @@ -4,7 +4,7 @@ class ConvertProjectToStateMachine < ActiveRecord::Migration def self.up add_column :projects, :state, :string, :limit => 20, :default => "active", :null => false - @projects = Project.find(:all) + @projects = Project.all @projects.each do |project| project.state = project.done? ? 'completed' : 'active' project.save @@ -14,7 +14,7 @@ class ConvertProjectToStateMachine < ActiveRecord::Migration def self.down add_column :projects, :done, :integer, :limit => 4, :default => 0, :null => false - @projects = Project.find(:all) + @projects = Project.all @projects.each do |project| project.done = project.state == 'completed' project.save diff --git a/db/migrate/019_convert_todo_to_state_machine.rb b/db/migrate/019_convert_todo_to_state_machine.rb index 84f2f843..775a4525 100644 --- a/db/migrate/019_convert_todo_to_state_machine.rb +++ b/db/migrate/019_convert_todo_to_state_machine.rb @@ -7,7 +7,7 @@ class ConvertTodoToStateMachine < ActiveRecord::Migration def self.up add_column :todos, :state, :string, :limit => 20, :default => "immediate", :null => false - @todos = Todo.find(:all) + @todos = Todo.all @todos.each do |todo| if todo.done? todo.state = 'completed' @@ -29,7 +29,7 @@ class ConvertTodoToStateMachine < ActiveRecord::Migration add_column :todos, :done, :integer, :limit => 4, :default => 0, :null => false add_column :todos, :type, :string, :default => "Immediate", :null => false rename_column :todos, 'completed_at', 'completed' #bug in sqlite requires column names as strings - @todos = Todo.find(:all) + @todos = Todo.all @todos.each do |todo| todo.done = todo.state == 'completed' todo.type = todo.type == 'deferred' ? 'Deferred' : 'Immediate' diff --git a/db/migrate/030_set_nil_timestamps.rb b/db/migrate/030_set_nil_timestamps.rb index 71ded287..4a605f31 100644 --- a/db/migrate/030_set_nil_timestamps.rb +++ b/db/migrate/030_set_nil_timestamps.rb @@ -5,16 +5,16 @@ class SetNilTimestamps < ActiveRecord::Migration class Context < ActiveRecord::Base; end def self.up - Project.find(:all, :conditions => { :created_at => nil }).each do |p| + Project.where(:created_at => nil ).each do |p| Project.update( p.id, {:created_at => Time.now.utc} ) end - Project.find(:all, :conditions => { :created_at => nil }).each do |p| + Project.where(:created_at => nil ).each do |p| Project.update( p.id, {:updated_at => Time.now.utc} ) end - Context.find(:all, :conditions => { :created_at => nil }).each do |p| + Context.where(:created_at => nil ).each do |p| Context.update( p.id, {:created_at => Time.now.utc} ) end - Context.find(:all, :conditions => { :created_at => nil }).each do |p| + Context.where(:created_at => nil ).each do |p| Context.update( p.id, {:updated_at => Time.now.utc} ) end diff --git a/db/migrate/035_update_open_id_urls.rb b/db/migrate/035_update_open_id_urls.rb index 19c7f681..7da779f2 100644 --- a/db/migrate/035_update_open_id_urls.rb +++ b/db/migrate/035_update_open_id_urls.rb @@ -16,7 +16,7 @@ class UpdateOpenIdUrls < ActiveRecord::Migration end def self.up - User.find(:all).each do |user| + User.all.each do |user| original = user.open_id_url user.normalize_open_id_url say "#{original} -> #{user.open_id_url}" diff --git a/db/migrate/036_add_project_completed_at_column.rb b/db/migrate/036_add_project_completed_at_column.rb index 86e16e73..de13b180 100644 --- a/db/migrate/036_add_project_completed_at_column.rb +++ b/db/migrate/036_add_project_completed_at_column.rb @@ -4,7 +4,7 @@ class AddProjectCompletedAtColumn < ActiveRecord::Migration def self.up add_column :projects, :completed_at, :datetime - @projects = Project.find(:all) + @projects = Project.all @projects.select{ |project| project.state == 'completed'}.each do |project| project.completed_at = project.updated_at project.save diff --git a/db/migrate/042_change_dates_to_datetimes.rb b/db/migrate/042_change_dates_to_datetimes.rb index d534c642..9c0b2ef6 100644 --- a/db/migrate/042_change_dates_to_datetimes.rb +++ b/db/migrate/042_change_dates_to_datetimes.rb @@ -5,7 +5,7 @@ class ChangeDatesToDatetimes < ActiveRecord::Migration change_column :recurring_todos, :start_from, :datetime change_column :recurring_todos, :end_date, :datetime - User.all(:include => [:todos, :recurring_todos]).each do |user| + User.includes(:todos, :recurring_todos).each do |user| if !user.prefs ## ugly hack for strange edge-case of not having preferences object user.instance_eval do def at_midnight(date) diff --git a/db/migrate/046_fix_incorrectly_hidden_todos.rb b/db/migrate/046_fix_incorrectly_hidden_todos.rb index 7ce294a9..1261954f 100644 --- a/db/migrate/046_fix_incorrectly_hidden_todos.rb +++ b/db/migrate/046_fix_incorrectly_hidden_todos.rb @@ -1,11 +1,11 @@ class FixIncorrectlyHiddenTodos < ActiveRecord::Migration def self.up hidden_todos_without_project = - Todo.find(:all, :conditions => "state='project_hidden' AND project_id IS NULL") + Todo.where(:state => 'project_hidden', :project_id => nil) - active_projects = Project.find(:all, :conditions => "state='active'") + active_projects = Project.where(:state => 'active') hidden_todos_in_active_projects = - Todo.find(:all, :conditions => ["state='project_hidden' AND project_id IN (?)", active_projects]) + Todo.where(:state => 'project_hidden').where("project_id IN (?)", active_projects) todos_to_fix = hidden_todos_without_project + hidden_todos_in_active_projects todos_to_fix.each do |todo| diff --git a/db/migrate/20090531111711_add_show_always_to_recurring_todo.rb b/db/migrate/20090531111711_add_show_always_to_recurring_todo.rb index 3ae6b8cc..210f6084 100644 --- a/db/migrate/20090531111711_add_show_always_to_recurring_todo.rb +++ b/db/migrate/20090531111711_add_show_always_to_recurring_todo.rb @@ -1,7 +1,7 @@ class AddShowAlwaysToRecurringTodo < ActiveRecord::Migration def self.up add_column :recurring_todos, :show_always, :boolean - recurring_todos = RecurringTodo.find(:all) + recurring_todos = RecurringTodo.all recurring_todos.each do |recurring_todo| if recurring_todo.show_from_delta == 0 or recurring_todo.show_from_delta.nil? recurring_todo.show_always = true diff --git a/db/migrate/20110621082432_make_old_recurring_todos_validate.rb b/db/migrate/20110621082432_make_old_recurring_todos_validate.rb index 51e06d05..1c9d9dc2 100644 --- a/db/migrate/20110621082432_make_old_recurring_todos_validate.rb +++ b/db/migrate/20110621082432_make_old_recurring_todos_validate.rb @@ -1,6 +1,6 @@ class MakeOldRecurringTodosValidate < ActiveRecord::Migration def self.up - RecurringTodo.find(:all).each do |rt| + RecurringTodo.all.each do |rt| # show_always may not be nil rt.show_always = false if rt.show_always.nil? # start date should be filled diff --git a/db/migrate/20120412072508_add_rendered_notes.rb b/db/migrate/20120412072508_add_rendered_notes.rb index 891dc28d..6b7ade60 100644 --- a/db/migrate/20120412072508_add_rendered_notes.rb +++ b/db/migrate/20120412072508_add_rendered_notes.rb @@ -6,7 +6,8 @@ class AddRenderedNotes < ActiveRecord::Migration say "Clearing show_from dates from completed todos" # clear up completed todos that have show_from set. These could have been left over from before the AASM migration - Todo.completed.find(:all, :conditions =>[ "NOT(show_from IS NULL)"]).each {|t| t.show_from=nil; t.save!} + Todo.completed.where( "NOT(show_from IS NULL)" ).each {|t| t.show_from=nil; t.save!} + say "Generating new column values from notes. This may take a while." # Call save! on each todo to force generation of rendered_todos i=0; max = Todo.all.count; start = Time.now diff --git a/lib/tracks/done_todos.rb b/lib/tracks/done_todos.rb index 36e08658..89cb1e3c 100644 --- a/lib/tracks/done_todos.rb +++ b/lib/tracks/done_todos.rb @@ -6,7 +6,8 @@ class DoneTodos def self.done_today(todos, includes = {:include => Todo::DEFAULT_INCLUDES}) start_of_this_day = Time.zone.now.beginning_of_day - todos.completed_after(start_of_this_day).all(includes) + # TODO: refactor to remove outer hash from includes param + todos.completed_after(start_of_this_day).includes(includes[:include]) end def self.done_rest_of_week(todos, includes = {:include => Todo::DEFAULT_INCLUDES}) @@ -37,6 +38,7 @@ class DoneTodos private def self.done_between(todos, includes, start_date, end_date) - todos.completed_before(start_date).completed_after(end_date).all(includes) + # TODO: refactor to remove outer hash from includes param + todos.completed_before(start_date).completed_after(end_date).includes(includes[:include]) end end