Optimise lookup of traces with a given tag.
authorTom Hughes <tom@compton.nu>
Fri, 12 Dec 2008 15:17:14 +0000 (15:17 +0000)
committerTom Hughes <tom@compton.nu>
Fri, 12 Dec 2008 15:17:14 +0000 (15:17 +0000)
app/controllers/trace_controller.rb

index 91ae92b05d653934fbed269e52345b44dbb421c9..bcac1184454aa1bffd5ab5694bbdbb88398ee85e 100644 (file)
@@ -48,8 +48,9 @@ class TraceController < ApplicationController
     
     if params[:tag]
       @tag = params[:tag]
-      conditions[0] += " AND EXISTS (SELECT * FROM gpx_file_tags AS gft WHERE gft.gpx_id = gpx_files.id AND gft.tag = ?)"
-      conditions << @tag
+
+      files = Tracetag.find_all_by_tag(params[:tag]).collect { |tt| tt.gpx_id }
+      conditions[0] += " AND gpx_files.id IN (#{files.join(',')})"
     end
     
     conditions[0] += " AND gpx_files.visible = 1"