mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-17 07:40:12 +01:00
revert refactoring that created a big performance regression
This commit is contained in:
parent
a58e832945
commit
f2d581d5a4
4 changed files with 38 additions and 17 deletions
|
|
@ -80,12 +80,22 @@ class ApplicationController < ActionController::Base
|
|||
# actions or multiple actions
|
||||
#
|
||||
def count_undone_todos_phrase(todos_parent, string="actions")
|
||||
count = todos_parent.nil? ? 0 : todos_parent.todos.not_completed.count
|
||||
# count_undone_todos(todos_parent)
|
||||
count = count_undone_todos(todos_parent)
|
||||
word = count == 1 ? string.singularize : string.pluralize
|
||||
return count.to_s + " " + word
|
||||
end
|
||||
|
||||
def count_undone_todos(todos_parent)
|
||||
if todos_parent.nil?
|
||||
count = 0
|
||||
elsif (todos_parent.is_a?(Project) && todos_parent.hidden?)
|
||||
count = eval "@project_project_hidden_todo_counts[#{todos_parent.id}]"
|
||||
else
|
||||
count = eval "@#{todos_parent.class.to_s.downcase}_not_done_counts[#{todos_parent.id}]"
|
||||
end
|
||||
count || 0
|
||||
end
|
||||
|
||||
# Convert a date object to the format specified in the user's preferences in
|
||||
# config/settings.yml
|
||||
#
|
||||
|
|
@ -256,6 +266,23 @@ class ApplicationController < ActionController::Base
|
|||
|
||||
@active_contexts = current_user.contexts.active
|
||||
@hidden_contexts = current_user.contexts.hidden
|
||||
|
||||
init_not_done_counts
|
||||
if prefs.show_hidden_projects_in_sidebar
|
||||
init_project_hidden_todo_counts(['project'])
|
||||
end
|
||||
end
|
||||
|
||||
def init_not_done_counts(parents = ['project','context'])
|
||||
parents.each do |parent|
|
||||
eval("@#{parent}_not_done_counts = @#{parent}_not_done_counts || current_user.todos.active.count(:group => :#{parent}_id)")
|
||||
end
|
||||
end
|
||||
|
||||
def init_project_hidden_todo_counts(parents = ['project','context'])
|
||||
parents.each do |parent|
|
||||
eval("@#{parent}_project_hidden_todo_counts = @#{parent}_project_hidden_todo_counts || current_user.todos.count(:conditions => ['state = ? or state = ?', 'project_hidden', 'active'], :group => :#{parent}_id)")
|
||||
end
|
||||
end
|
||||
|
||||
# Set the contents of the flash message from a controller Usage: notify
|
||||
|
|
|
|||
|
|
@ -263,7 +263,7 @@ class ContextsController < ApplicationController
|
|||
def init_todos
|
||||
set_context_from_params
|
||||
unless @context.nil?
|
||||
@context.todos.send :with_scope, :find => { :include => [:project, :tags, :successors, :predecessors, :recurring_todo] } do
|
||||
@context.todos.send :with_scope, :find => { :include => Todo::DEFAULT_INCLUDES } do
|
||||
@done = @context.done_todos
|
||||
end
|
||||
|
||||
|
|
@ -275,7 +275,7 @@ class ContextsController < ApplicationController
|
|||
# projects from context.
|
||||
@not_done_todos = @context.todos.active(
|
||||
:order => "todos.due IS NULL, todos.due ASC, todos.created_at ASC",
|
||||
:include => [:project, :tags, :successors, :predecessors, :recurring_todo])
|
||||
:include => Todo::DEFAULT_INCLUDES)
|
||||
|
||||
@projects = current_user.projects
|
||||
|
||||
|
|
|
|||
|
|
@ -45,11 +45,11 @@ class ProjectsController < ApplicationController
|
|||
init_data_for_sidebar unless mobile?
|
||||
@page_title = t('projects.page_title', :project => @project.name)
|
||||
|
||||
@not_done = @project.todos.active_or_hidden(:include => [:tags, :context, :predecessors])
|
||||
@deferred = @project.todos.deferred(:include => [:tags, :context, :predecessors])
|
||||
@pending = @project.todos.pending(:include => [:tags, :context, :predecessors])
|
||||
@not_done = @project.todos.active_or_hidden(:include => Todo::DEFAULT_INCLUDES)
|
||||
@deferred = @project.todos.deferred(:include => Todo::DEFAULT_INCLUDES)
|
||||
@pending = @project.todos.pending(:include => Todo::DEFAULT_INCLUDES)
|
||||
@done = @project.todos.find_in_state(:all, :completed,
|
||||
:order => "todos.completed_at DESC", :limit => current_user.prefs.show_number_completed, :include => [:context, :tags, :predecessors])
|
||||
:order => "todos.completed_at DESC", :limit => current_user.prefs.show_number_completed, :include => Todo::DEFAULT_INCLUDES)
|
||||
|
||||
@count = @not_done.size
|
||||
@down_count = @count + @deferred.size + @pending.size
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ class Todo < ActiveRecord::Base
|
|||
named_scope :completed_before, lambda { |date| {:conditions => ["todos.completed_at < ? ", date] } }
|
||||
|
||||
STARRED_TAG_NAME = "starred"
|
||||
DEFAULT_INCLUDES = [ :project, :context, :tags, :taggings, :recurring_todo ]
|
||||
DEFAULT_INCLUDES = [ :project, :context, :tags, :taggings, :pending_successors, :uncompleted_predecessors, :recurring_todo ]
|
||||
|
||||
# regular expressions for dependencies
|
||||
RE_TODO = /[^']+/
|
||||
|
|
@ -185,13 +185,7 @@ class Todo < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def has_pending_successors
|
||||
# has_many :pending_successors, :through => :predecessor_dependencies,
|
||||
# :source => :successor, :conditions => ['todos.state = ?', 'pending']
|
||||
|
||||
successors = predecessor_dependencies.all(:include => [:successor])
|
||||
pending = successors.reject { |d| !( d.successor.state=='pending') }
|
||||
return !pending.empty?
|
||||
#return !pending_successors.empty?
|
||||
return !pending_successors.empty?
|
||||
end
|
||||
|
||||
def has_tag?(tag)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue