mirror of
https://github.com/TracksApp/tracks.git
synced 2026-02-27 01:24:07 +01:00
#923: Applied Reinier's patch for reducing DB access on predecessor autocomplete.
This commit is contained in:
parent
1f9b77faf4
commit
54dc1ad047
1 changed files with 15 additions and 2 deletions
|
|
@ -6,8 +6,8 @@ class TodosController < ApplicationController
|
||||||
prepend_before_filter :login_or_feed_token_required, :only => [:index, :calendar]
|
prepend_before_filter :login_or_feed_token_required, :only => [:index, :calendar]
|
||||||
append_before_filter :init, :except => [ :destroy, :completed,
|
append_before_filter :init, :except => [ :destroy, :completed,
|
||||||
:completed_archive, :check_deferred, :toggle_check, :toggle_star,
|
:completed_archive, :check_deferred, :toggle_check, :toggle_star,
|
||||||
:edit, :update, :create, :calendar, :auto_complete_for_tag]
|
:edit, :update, :create, :calendar, :auto_complete_for_tag, :auto_complete_for_predecessor, :remove_predecessor, :add_predecessor]
|
||||||
append_before_filter :get_todo_from_params, :only => [ :edit, :toggle_check, :toggle_star, :show, :update, :destroy ]
|
append_before_filter :get_todo_from_params, :only => [ :edit, :toggle_check, :toggle_star, :show, :update, :destroy, :remove_predecessor]
|
||||||
protect_from_forgery :except => [:auto_complete_for_tag, :auto_complete_for_predecessor]
|
protect_from_forgery :except => [:auto_complete_for_tag, :auto_complete_for_predecessor]
|
||||||
|
|
||||||
session :off, :only => :index, :if => Proc.new { |req| is_feed_request(req) }
|
session :off, :only => :index, :if => Proc.new { |req| is_feed_request(req) }
|
||||||
|
|
@ -154,6 +154,16 @@ class TodosController < ApplicationController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def remove_predecessor
|
||||||
|
@source_view = params['_source_view'] || 'todo'
|
||||||
|
@predecessor = Todo.find(params['predecessor'])
|
||||||
|
@successor = @todo
|
||||||
|
@removed = @successor.remove_predecessor(@predecessor)
|
||||||
|
respond_to do |format|
|
||||||
|
format.js
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# Toggles the 'done' status of the action
|
# Toggles the 'done' status of the action
|
||||||
#
|
#
|
||||||
def toggle_check
|
def toggle_check
|
||||||
|
|
@ -594,6 +604,7 @@ class TodosController < ApplicationController
|
||||||
get_todo_from_params
|
get_todo_from_params
|
||||||
# Begin matching todos in current project
|
# Begin matching todos in current project
|
||||||
@items = current_user.todos.find(:all,
|
@items = current_user.todos.find(:all,
|
||||||
|
:select => :description,
|
||||||
:conditions => [ '(todos.state = ? OR todos.state = ?) AND ' +
|
:conditions => [ '(todos.state = ? OR todos.state = ?) AND ' +
|
||||||
'NOT (id = ?) AND lower(description) LIKE ? AND project_id = ?',
|
'NOT (id = ?) AND lower(description) LIKE ? AND project_id = ?',
|
||||||
'active', 'pending',
|
'active', 'pending',
|
||||||
|
|
@ -605,6 +616,7 @@ class TodosController < ApplicationController
|
||||||
)
|
)
|
||||||
if @items.empty? # Match todos in other projects
|
if @items.empty? # Match todos in other projects
|
||||||
@items = current_user.todos.find(:all,
|
@items = current_user.todos.find(:all,
|
||||||
|
:select => :description,
|
||||||
:conditions => [ '(todos.state = ? OR todos.state = ?) AND ' +
|
:conditions => [ '(todos.state = ? OR todos.state = ?) AND ' +
|
||||||
'NOT (id = ?) AND lower(description) LIKE ?',
|
'NOT (id = ?) AND lower(description) LIKE ?',
|
||||||
'active', 'pending',
|
'active', 'pending',
|
||||||
|
|
@ -616,6 +628,7 @@ class TodosController < ApplicationController
|
||||||
else
|
else
|
||||||
# New todo - TODO: Filter on project
|
# New todo - TODO: Filter on project
|
||||||
@items = current_user.todos.find(:all,
|
@items = current_user.todos.find(:all,
|
||||||
|
:select => :description,
|
||||||
:conditions => [ '(todos.state = ? OR todos.state = ?) AND lower(description) LIKE ?',
|
:conditions => [ '(todos.state = ? OR todos.state = ?) AND lower(description) LIKE ?',
|
||||||
'active', 'pending',
|
'active', 'pending',
|
||||||
'%' + params[:predecessor_list].downcase + '%' ],
|
'%' + params[:predecessor_list].downcase + '%' ],
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue