Fix issue where completed items would redundantly show context on a context page and project on a project page.

Eliminated some N+1 query generation issues on context and project detail pages related to looking up tags.
Added rake task to turn on and off the mysql query_analyzer plugin, which I'm using to help in my optimization process.



git-svn-id: http://www.rousette.org.uk/svn/tracks-repos/trunk@662 a4c988fc-2ded-0310-b66e-134b36920a42
This commit is contained in:
lukemelia 2007-11-27 05:51:38 +00:00
parent 1516d7ae14
commit 0f823a8a2e
9 changed files with 55 additions and 16 deletions

View file

@ -155,12 +155,14 @@ class ContextsController < ApplicationController
def init_todos
set_context_from_params
unless @context.nil?
@done = @context.done_todos
@context.todos.with_scope :find => { :include => [:project, :tags] } do
@done = @context.done_todos
end
# @not_done_todos = @context.not_done_todos
# TODO: Temporarily doing this search manually until I can work out a way
# to do the same thing using not_done_todos acts_as_todo_container method
# Hides actions in hidden projects from context.
@not_done_todos = @context.todos.find(:all, :conditions => ['todos.state = ?', 'active'], :order => "todos.due IS NULL, todos.due ASC, todos.created_at ASC", :include => :project)
@not_done_todos = @context.todos.find(:all, :conditions => ['todos.state = ?', 'active'], :order => "todos.due IS NULL, todos.due ASC, todos.created_at ASC", :include => [:project, :tags])
@count = @not_done_todos.size
@default_project_context_name_map = build_default_project_context_name_map(@projects).to_json
end

View file

@ -27,9 +27,11 @@ class ProjectsController < ApplicationController
def show
init_data_for_sidebar
@page_title = "TRACKS::Project: #{@project.name}"
@not_done = @project.not_done_todos(:include_project_hidden_todos => true)
@deferred = @project.deferred_todos.sort_by { |todo| todo.show_from }
@done = @project.done_todos
@project.todos.with_scope :find => { :include => [:context, :tags] } do
@not_done = @project.not_done_todos(:include_project_hidden_todos => true)
@deferred = @project.deferred_todos.sort_by { |todo| todo.show_from }
@done = @project.done_todos
end
@count = @not_done.size
@next_project = current_user.projects.next_from(@project)
@previous_project = current_user.projects.previous_from(@project)

View file

@ -93,19 +93,23 @@ module TodosHelper
end
end
def project_and_context_links(parent_container_type)
def project_and_context_links(parent_container_type, opts = {})
str = ''
if @todo.completed?
"(#{@todo.context.name}#{", " + @todo.project.name unless @todo.project.nil?})"
str += @todo.context.name unless opts[:suppress_context]
should_suppress_project = opts[:suppress_project] || @todo.project.nil?
str += ", " unless str.blank? || should_suppress_project
str += @todo.project.name unless should_suppress_project
str = "(#{str})" unless str.blank?
else
str = ''
if (['project', 'tag'].include?(parent_container_type))
str << item_link_to_context( @todo )
end
if (['context', 'tickler', 'tag'].include?(parent_container_type)) && @todo.project_id
str << item_link_to_project( @todo )
end
str
end
return str
end
# Uses the 'staleness_starts' value from settings.yml (in days) to colour the

View file

@ -1,6 +1,6 @@
<div id="display_box">
<%= render :partial => "contexts/context", :locals => { :context => @context, :collapsible => false } %>
<%= render :partial => "todos/completed", :locals => { :done => @done, :collapsible => false, :append_descriptor => "in this context (last #{prefs.show_number_completed})" } %>
<%= render :partial => "todos/completed", :locals => { :done => @done, :suppress_context => true, :collapsible => false, :append_descriptor => "in this context (last #{prefs.show_number_completed})" } %>
</div><!-- [end:display_box] -->

View file

@ -5,7 +5,7 @@
<%= render :partial => "projects/project", :locals => { :project => @project, :collapsible => false } %>
<%= render :partial => "todos/deferred", :locals => { :deferred => @deferred, :collapsible => false, :append_descriptor => "in this project" } %>
<%= render :partial => "todos/completed", :locals => { :done => @done, :collapsible => false, :append_descriptor => "in this project" } %>
<%= render :partial => "todos/completed", :locals => { :done => @done, :collapsible => false, :suppress_project => true, :append_descriptor => "in this project" } %>
<div class="container">
<div id="notes">

View file

@ -1,10 +1,13 @@
<% suffix = append_descriptor ? append_descriptor : '' -%>
<% suffix = append_descriptor ? append_descriptor : ''
suppress_context ||= false
suppress_project ||= false
-%>
<div class="container completed" id="completed_container">
<h2>
<% if collapsible %>
<a href="#" class="container_toggle" id="toggle_completed"><%= image_tag("collapse.png") %></a>
<% end %>
Completed actions <%= append_descriptor ? append_descriptor : '' %>
Completed actions <%= suffix %>
</h2>
<div id="completed" class="items toggle_target">
@ -12,6 +15,6 @@
<div class="message"><p>Currently there are no completed actions.</p></div>
</div>
<%= render :partial => "todos/todo", :collection => done, :locals => { :parent_container_type => "completed" } %>
<%= render :partial => "todos/todo", :collection => done, :locals => { :parent_container_type => "completed", :suppress_context => suppress_context, :suppress_project => suppress_project } %>
</div>
</div><!-- [end:next_actions] -->

View file

@ -1,5 +1,7 @@
<%
@todo = todo
suppress_context ||= false
suppress_project ||= false
%>
<div id="<%= dom_id(todo) %>" class="item-container">
<div id="<%= dom_id(todo, 'line') %>">
@ -12,7 +14,7 @@
<%= sanitize(todo.description) %>
<%= tag_list %>
<%= deferred_due_date %>
<%= project_and_context_links( parent_container_type ) %>
<%= project_and_context_links( parent_container_type, :suppress_context => suppress_context, :suppress_project => suppress_project ) %>
<%= render(:partial => "todos/toggle_notes", :locals => { :item => todo }) if todo.notes? %>
</div>
</div>

View file

@ -21,4 +21,30 @@ namespace :query_trace do
FileUtils.rm_rf("#{RAILS_ROOT}/vendor/plugins/query_trace")
puts "QueryTrace plugin disabled. Must restart server to take effect."
end
end
end
namespace :query_analyzer do
desc "Enables the query_analyzer plugin. Must restart server to take effect."
task :on => :environment do
unless File.exist?("#{RAILS_ROOT}/vendor/query_analyzer.tar.gz")
Dir.chdir("#{RAILS_ROOT}/vendor") do
url = "http://svn.nfectio.us/plugins/query_analyzer"
puts "Loading query_analyzer from #{url}..."
system "svn co #{url} query_analyzer"
system "tar zcf query_analyzer.tar.gz --exclude=.svn query_analyzer"
FileUtils.rm_rf("query_analyzer")
end
end
Dir.chdir("#{RAILS_ROOT}/vendor/plugins") do
system "tar zxf ../query_analyzer.tar.gz query_analyzer"
end
puts "QueryAnalyzer plugin enabled. Must restart server to take effect."
end
desc "Disables the query_analyzer plugin. Must restart server to take effect."
task :off => :environment do
FileUtils.rm_rf("#{RAILS_ROOT}/vendor/plugins/query_analyzer")
puts "QueryAnalyzer plugin disabled. Must restart server to take effect."
end
end

BIN
tracks/vendor/query_analyzer.tar.gz vendored Normal file

Binary file not shown.