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
|
# actions or multiple actions
|
||||||
#
|
#
|
||||||
def count_undone_todos_phrase(todos_parent, string="actions")
|
def count_undone_todos_phrase(todos_parent, string="actions")
|
||||||
count = todos_parent.nil? ? 0 : todos_parent.todos.not_completed.count
|
count = count_undone_todos(todos_parent)
|
||||||
# count_undone_todos(todos_parent)
|
|
||||||
word = count == 1 ? string.singularize : string.pluralize
|
word = count == 1 ? string.singularize : string.pluralize
|
||||||
return count.to_s + " " + word
|
return count.to_s + " " + word
|
||||||
end
|
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
|
# Convert a date object to the format specified in the user's preferences in
|
||||||
# config/settings.yml
|
# config/settings.yml
|
||||||
#
|
#
|
||||||
|
|
@ -256,8 +266,25 @@ class ApplicationController < ActionController::Base
|
||||||
|
|
||||||
@active_contexts = current_user.contexts.active
|
@active_contexts = current_user.contexts.active
|
||||||
@hidden_contexts = current_user.contexts.hidden
|
@hidden_contexts = current_user.contexts.hidden
|
||||||
end
|
|
||||||
|
|
||||||
|
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
|
# Set the contents of the flash message from a controller Usage: notify
|
||||||
# :warning, "This is the message" Sets the flash of type 'warning' to "This is
|
# :warning, "This is the message" Sets the flash of type 'warning' to "This is
|
||||||
# the message"
|
# the message"
|
||||||
|
|
|
||||||
|
|
@ -263,7 +263,7 @@ class ContextsController < ApplicationController
|
||||||
def init_todos
|
def init_todos
|
||||||
set_context_from_params
|
set_context_from_params
|
||||||
unless @context.nil?
|
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
|
@done = @context.done_todos
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -275,7 +275,7 @@ class ContextsController < ApplicationController
|
||||||
# projects from context.
|
# projects from context.
|
||||||
@not_done_todos = @context.todos.active(
|
@not_done_todos = @context.todos.active(
|
||||||
:order => "todos.due IS NULL, todos.due ASC, todos.created_at ASC",
|
: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
|
@projects = current_user.projects
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -45,11 +45,11 @@ class ProjectsController < ApplicationController
|
||||||
init_data_for_sidebar unless mobile?
|
init_data_for_sidebar unless mobile?
|
||||||
@page_title = t('projects.page_title', :project => @project.name)
|
@page_title = t('projects.page_title', :project => @project.name)
|
||||||
|
|
||||||
@not_done = @project.todos.active_or_hidden(:include => [:tags, :context, :predecessors])
|
@not_done = @project.todos.active_or_hidden(:include => Todo::DEFAULT_INCLUDES)
|
||||||
@deferred = @project.todos.deferred(:include => [:tags, :context, :predecessors])
|
@deferred = @project.todos.deferred(:include => Todo::DEFAULT_INCLUDES)
|
||||||
@pending = @project.todos.pending(:include => [:tags, :context, :predecessors])
|
@pending = @project.todos.pending(:include => Todo::DEFAULT_INCLUDES)
|
||||||
@done = @project.todos.find_in_state(:all, :completed,
|
@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
|
@count = @not_done.size
|
||||||
@down_count = @count + @deferred.size + @pending.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] } }
|
named_scope :completed_before, lambda { |date| {:conditions => ["todos.completed_at < ? ", date] } }
|
||||||
|
|
||||||
STARRED_TAG_NAME = "starred"
|
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
|
# regular expressions for dependencies
|
||||||
RE_TODO = /[^']+/
|
RE_TODO = /[^']+/
|
||||||
|
|
@ -185,13 +185,7 @@ class Todo < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def has_pending_successors
|
def has_pending_successors
|
||||||
# has_many :pending_successors, :through => :predecessor_dependencies,
|
return !pending_successors.empty?
|
||||||
# :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?
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def has_tag?(tag)
|
def has_tag?(tag)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue