]> git.openstreetmap.org Git - rails.git/commitdiff
Remove nearby_place from the note model
authorKai Krueger <kakrueger@gmail.com>
Tue, 20 Nov 2012 23:10:07 +0000 (16:10 -0700)
committerTom Hughes <tom@compton.nu>
Sat, 1 Dec 2012 18:18:09 +0000 (18:18 +0000)
Instead of storing the auto-generated meta information nearby_place
in the database, just look up the information on the fly when needed
and cache it for performance.

app/controllers/notes_controller.rb
app/views/notes/_note.json.jsonify
app/views/notes/_note.rss.builder
app/views/notes/_note.xml.builder
app/views/notes/feed.rss.builder
db/migrate/20121119165817_drop_nearby_place_from_notes.rb [new file with mode: 0644]

index 2089c2289ecaafc6cd704571643df657b346727b..5a09342474e25906c2489df86604e8ff2cc233ca 100644 (file)
@@ -66,20 +66,6 @@ class NotesController < ApplicationController
       @note = Note.create(:lat => lat, :lon => lon)
       raise OSM::APIBadUserInput.new("The note is outside this world") unless @note.in_world?
 
-      #TODO: move this into a helper function
-      begin
-        url = "http://nominatim.openstreetmap.org/reverse?lat=" + lat.to_s + "&lon=" + lon.to_s + "&zoom=16" 
-        response = REXML::Document.new(Net::HTTP.get(URI.parse(url))) 
-               
-        if result = response.get_text("reversegeocode/result") 
-          @note.nearby_place = result.to_s 
-        else 
-          @note.nearby_place = "unknown"
-        end
-      rescue Exception => err
-        @note.nearby_place = "unknown"
-      end
-
       # Save the note
       @note.save!
 
index 6afb4a555b9e5d0b1de6673563901a5781a597ab..f252a0dfc41b930c4e00e4aae0503f3eebe14f78 100644 (file)
@@ -11,7 +11,6 @@ json.properties do
   json.comment_url comment_note_url(note, :format => params[:format])
   json.close_url close_note_url(note, :format => params[:format])
   json.date_created note.created_at
-  json.nearby  note.nearby_place
   json.status note.status
   json.closed_at note.closed_at if note.status == "closed"
 
index bae719f5f3e1868d904e0b8300b2688c237d430d..efdae52bb5365e79e31d41c406cb6cbc7947d18f 100644 (file)
@@ -1,16 +1,19 @@
 xml.item do
+  location_string = Rails.cache.fetch("location_description_#{note.lat}_#{note.lon}_#{locale}") do
+    describe_location note.lat, note.lon, 14, locale
+  end 
   if note.status == "closed"
-    xml.title t('note.rss.closed', :place => note.nearby_place)        
+    xml.title t('note.rss.closed', :place => location_string)  
   elsif note.comments.length > 1
-    xml.title t('note.rss.comment', :place => note.nearby_place)
+    xml.title t('note.rss.comment', :place => location_string)
   else
-    xml.title t('note.rss.new', :place => note.nearby_place)
+    xml.title t('note.rss.new', :place => location_string)
   end
 
   xml.link browse_note_url(note)
   xml.guid note_url(note)
   xml.description render(:partial => "description", :object => note, :formats => [ :html ])
-  xml.author note.author_name
+  xml.author note.comments.first.author_name
   xml.pubDate note.updated_at.to_s(:rfc822)
   xml.geo :lat, note.lat
   xml.geo :long, note.lon
index c00b49c73ba95d5857c5801a5236bdced5e17a82..a68946bb7a7e46ff9eeb83594052f3fb238ee183 100644 (file)
@@ -4,7 +4,6 @@ xml.note("lon" => note.lon, "lat" => note.lat) do
   xml.comment_url comment_note_url(note, :format => params[:format])
   xml.close_url close_note_url(note, :format => params[:format])  
   xml.date_created note.created_at
-  xml.nearby note.nearby_place
   xml.status note.status
 
   if note.status == "closed"
index dd7d32c5f5c19e976488cd323cd53fa3ce0992b9..ba0e3fbfecdfa5ca6149358e3f4dbe8f961124f6 100644 (file)
@@ -9,13 +9,16 @@ xml.rss("version" => "2.0",
     xml.link url_for(:controller => "site", :action => "index", :only_path => false)
 
     @comments.each do |comment|
+      location_string = Rails.cache.fetch("location_description_#{comment.note.lat}_#{comment.note.lon}_#{locale}") do
+        describe_location comment.note.lat, comment.note.lon, 14, locale
+      end
       xml.item do
         if comment.event == "closed"
-          xml.title t('note.rss.closed', :place => comment.note.nearby_place)  
+          xml.title t('note.rss.closed', :place => location_string)    
         elsif comment.event == "commented"
-          xml.title t('note.rss.comment', :place => comment.note.nearby_place)
+          xml.title t('note.rss.comment', :place => location_string)
         elsif comment.event == "opened"
-          xml.title t('note.rss.new', :place => comment.note.nearby_place)
+          xml.title t('note.rss.new', :place => location_string)
         else
           xml.title "unknown event"
         end
diff --git a/db/migrate/20121119165817_drop_nearby_place_from_notes.rb b/db/migrate/20121119165817_drop_nearby_place_from_notes.rb
new file mode 100644 (file)
index 0000000..bbef259
--- /dev/null
@@ -0,0 +1,9 @@
+class DropNearbyPlaceFromNotes < ActiveRecord::Migration
+  def up
+    remove_column :notes, :nearby_place
+  end
+
+  def down
+    add_column :notes, :nearby_place, :string
+  end
+end