Rewrite tag search SQL to use JOIN instead of WHERE when appropriate.

Signed-off-by: Reinier Balt <lrbalt@gmail.com>
This commit is contained in:
Farzad FARID 2009-01-22 06:34:29 +08:00 committed by Reinier Balt
parent 2472866baa
commit 609cd181b6

View file

@ -13,12 +13,11 @@ class SearchController < ApplicationController
# TODO: limit search to tags on todos
@found_tags = Tagging.find_by_sql([
"SELECT DISTINCT tags.name as name "+
"FROM tags, taggings, todos "+
"FROM tags "+
"LEFT JOIN taggings ON tags.id = taggings.tag_id "+
"LEFT JOIN todos ON taggings.taggable_id = todos.id "+
"WHERE todos.user_id=? "+
"AND tags.name LIKE ? " +
"AND tags.id = taggings.tag_id " +
"AND taggings.taggable_id = todos.id ", current_user.id, terms])
#current_user.tags.find(:all, :conditions => ["name LIKE ?", terms])
"AND tags.name LIKE ? ", current_user.id, terms])
@count = @found_todos.size + @found_projects.size + @found_notes.size + @found_contexts.size + @found_tags.size